I am using rails 2.3.17, I have used fedex .
How can I validate the shipping address using fedex?
Is there any proper documentation for the fedex api to validate address?
Any help is appreciated.
Thanks
EDIT
I have used the plugin https://github.com/kdonovan/fedex
Please have a look on it
Honestly don't use FedEx's API to do address resi/comm versification. Its fraught with error, I've actually fed it FedEx owned warehouse locations and it told me they were residential. It may cost money but its better to use a third party like a smartystreets.com or someone like that.
If you have a set of fedex creds you can visit http://www.fedex.com/us/developer/ and get the API guides etc. I will say that some of their API's have errors in them so depending on what you're trying to do you can get some interesting results.
I assume you are referring to the fedex gem.
You can find this example of address validation in the docs:
address = {
:address => "5 Elm Street",
:city => "Norwalk",
:state => "CT",
:postal_code => "06850",
:country => "USA"
}
address_result = fedex.validate_address(:address => address)
address_result.residential
# => true
address_result.score
# => 100
address_result.postal_code
# => "06850-3901"
Related
This question is an expanded version of Facebook Real-time updated does not call our servers, that seems to be dead. Also, Realtime updates internal server error on Heroku using Koala is not helpful because I'm subscribing from the heroku console as pjaspers suggested.
I have an app (ruby 1.9.2p290 and Rails 3.1.3) that connects to facebook to get data from the current user. Everything is working ok with the koala gem (v1.2.1), but I'm polling the fb servers every time the users logs in. I would like to use facebook real-time updates, and I have read the following:
Koala manual on fb realtime updates: https://github.com/arsduo/koala/wiki/Realtime-Updates
Facebook page on realtime: https://developers.facebook.com/docs/reference/api/realtime/
I have set up the system in test mode and deployed to heroku successfully. I can subscribe to the user object and I get the GET request to my server, but no POST with updated information is ever received from facebook. If I issue a POST to my server manually everything works.
More information:
routes.rb
get '/realtime' => 'realtime#verify'
post '/realtime' => 'realtime#change'
generating
realtime GET /realtime(.:format) {:controller=>"realtime", :action=>"verify"}
POST /realtime(.:format) {:controller=>"realtime", :action=>"change"}
The controller (mock version, only to test if it's working):
class RealtimeController < ApplicationController
def verify
render :text => params["hub.challenge"]
end
def change
puts params.inspect
render :nothing => true
end
end
The subscription from the heroku console:
irb(main):004:0> #updates = Koala::Facebook::RealtimeUpdates.new(:app_id => ENV['FACEBOOK_APP_ID'], :secret => ENV['FACEBOOK_APP_SECRET'])
=> #<Koala::Facebook::RealtimeUpdates:0x00000004f5bca8 #app_id="XXXXXXX", #app_access_token="XXXXXXX", #secret="XXXXXXX", #graph_api=#<Koala::Facebook::API:0x00000004a8d7a8 #access_token="XXXXXXX">>
irb(main):005:0> #updates.list_subscriptions
=> [{"object"=>"user", "callback_url"=>"http://blah-blah-0000.herokuapp.com/realtime", "fields"=>["education", "email", "friends", "name", "website", "work"], "active"=>true}]
I don't know what to do next...
Maybe I am not triggering the correct changing events?
How do I see the list of users of my app? (right now it's a test app and the only user would be me)
Anyone with this kind of issue?
Is something wrong in the code?
Is facebook down? Is it the end of Internet?
Thank you for the help :)
You need to respond to the GET request with a challenge response. I have the same route for both POST and GET requests and use the following code:
route:
match "facebook/subscription", :controller => :facebook, :action => :subscription, :as => 'facebook_subscription', :via => [:get,:post]
controller:
def realtime_request?(request)
((request.method == "GET" && params['hub.mode'].present?) ||
(request.method == "POST" && request.headers['X-Hub-Signature'].present?))
end
def subscription
if(realtime_request?(request))
case request.method
when "GET"
challenge = Koala::Facebook::RealtimeUpdates.meet_challenge(params,'SOME_TOKEN_HERE')
if(challenge)
render :text => challenge
else
render :text => 'Failed to authorize facebook challenge request'
end
when "POST"
case params['object']
# Do logic here...
render :text => 'Thanks for the update.'
end
end
end
That should get you going with things... Note that to make a subscription I am using this:
#access_token ||= Koala::Facebook::OAuth.new(FACEBOOK_API_KEY,FACEBOOK_API_SECRET).get_app_access_token
#realtime = Koala::Facebook::RealtimeUpdates.new(:app_id => FACEBOOK_API_KEY, :app_access_token => #access_token)
#realtime.subscribe('user', 'first_name,uid,etc...', facebook_subscription_url,'SOME_TOKEN_HERE')
I think the key is that you properly respond to the GET request from Facebook. They use this to verify that they are contacting the correct server prior to sending confidential info about their users.
Also -- its been a while since I've looked at this, but if I remember correctly, I seem to recall having issues with anything besides default protocol port specifications within the callback URL. Ex: http://www.something.com:8080/subscription did not work -- it had to be http://www.something.com/subscription
Not sure if this might be the case with you, but make sure that you have permissions to access the object -user, permissions, page- properties (location, email, etc.)
In my case, I was trying to get notifications for changes on the location property without my app requiring the user_location permission. For the user object, look at the Fields section in this page https://developers.facebook.com/docs/reference/api/user/
Does Facebook know where your application is? Does it have a URL that it can resolve?
I am learning how to write APIs in Rails. I managed to write an API to create an object. However, I'm facing issues on how to invoke it.
Routes.rb
namespace :api do
namespace :v1 do
resources :company_donations
end
end
App/Controllers/Api/v1/Company_donation_controller has create method which requires 3 objects to be passed token, api_key and an object called donation with variables amount and comment.
Now I want to test my own API. How do I call this post API from a rake task? Use open-uri? How do I invoke following code?
post "http://localhost:3000/api/v1/company_donations.json", :token => "HusGbrnhi2s3EmUB7fHH",
:api_key => "f70aa490-dc2a-012e-da4e-442c03154814",
:donation => {
:amount => 101,
:comment => "Ordered 2 books"
}
Apologise for answering my own question. I eventually used - Nestful.post library helped.
In my app I've got various resources that I want to access via multiple URLs. For example, an invoice can be accessed via:
/invoices/:id
By the issuer of the invoice, and also via:
/pay/:payment_key
By the payer.
The latter URL does not require authentication (hence the secrefied payment_key).
The issue is how to get automatic URL helper methods for the custom URL. Usually you could use to_param to customize the resource URL (as described here), but that's not adequate in this case because I still want to retain the default resource URL.
If I create the helper methods by declaring a named route:
/pay/:payment_key, :as => :invoice_payment
Then I would expect invoice_payment_url(invoice) to include invoice.payment_key but it doesn't. Rails uses the invoice ID instead (similar to the behaviour reported here)
This seems like it's broken.
So I've been defining the url helpers for this resource manually.
def invoice_payment_path (invoice)
url_for :controller => "invoices",
:only_path => true,
:action => "pay",
:payment_key => invoice.payment_key
end
def invoice_payment_url (invoice)
url_for :controller => "invoices",
:only_path => false,
:action => "pay",
:payment_key => invoice.payment_key
end
Wondering if there is a DRYer way to do this?
RESTful is about resources. So are you sure the "payment" and "invoice" resources the same thing in your system? To me, it is more like a system design issue than a routing issue.
Another thought is using nested resources. You can view either "/payments/:id/invoices" or "/invoices/:id/payments", both make sense to me.
Yan
The :bcc field doesn't seem to work.
mail(:to => "xx#xxx.org",
:bcc => "xx1#xxx.org",
:subject => "Welcome to My Awesome Site")
I want to pass to the :BCC field an array of 100 e-mails to send but this doesn't work even when I pass only 1 value.
Thanks
I just ran into this as well. However, I narrowed it down to my use of SES for delivery. I found this issue
https://github.com/drewblas/aws-ses/issues/16
When I used sendmail, the bcc worked just fine.
I have a Rails 3.0 web app that allow user to create own path to the application.
example : www.my_app.com/user_company_name
So I store a custom path in user DB field. User can changing path throught a input.
I have added this validation in model
validates_presence_of :custom_page
validates_format_of :custom_page, :with => /^([a-z]|[0-9]|\-|_)+$/, :message => "Only letter (small caps), number, underscore and - are authorized"
validates_length_of :custom_page, :minimum => 3
validates_uniqueness_of :custom_page, :case_sensitive => false
But I don't know how I can validate url to check it isn't in conflict with another route in my routing.
For example in my route.rb I have
resources :user
Validation need to don't allow using www.my_app.com/user, how I can do that?
Thanks, vincent
In your routes, you match the company name to a variable
match 'some_path/:company_name.format'
you can then do the lookup using company_name which rails will populate for you.
Validating the uniqueness of the custom_page variable should be enough to ensure there's no overlap. (note that validate uniqueness of doesn't scale -- if this will be big, you need a db constraint as well) as long as users can only specify one field.
If you're letting users specify
'some_path/:custom_path_1/:custom_path_2.format'
then you have to validate across both fields, and now it's getting messy. Hope you're not doing that.
You can try a custom validation to weed out "user"
validate :custom_page_cant_be_user
def custom_page_cant_be_user
errors.add(:custom_page, "can't be `user`") if self.custom_page =~ /^user$/i
end
assuming :custom_page comes in as a basic [a-z], if :custom_page has /user you need to update the regex a bit.