Docmail API for ROR application for postcard - ruby-on-rails

I am using docmail's Simple API for sending Postcard.They have implemented this functionality recently, but I didn't get any sample code or instruction for implementation.
Thanks in advance,
Gaurav Soni

I got my answer.Here is a sample code that can interact with Docmail Simple API methods.
require "base64"
require "soap/wsdlDriver"
class TestDocmailLetterSending
def initialize(account)
api="https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?wsdl"
#test = SOAP::WSDLDriverFactory.new(api).create_rpc_driver
contents = open(file, "rb") do |f|
f.read
end
result = #test.sendLetterToSingleAddress(
'sUsr' => "username",
'sPwd' => "password",
'sMailingName' => "string",
'sCallingApplicationID' => "string",
'bColour' => true,
'bDuplex' => true or false,
'eDeliveryType' => "StandardClass",
'sTemplateFileName' => File.basename(file),
'eAddressNameFormat' => "FullName",
'bTemplateData' => contents,
'sFirstName' => first_name,
'sLastName' => last_name,
'sAddress1' => "",
'sAddress2' => ,
'sAddress3' => ,
'sAddress4' => ,
'sPostCode' => ,
'bProofApprovalRequired' => 'false'
)
end
end

We don't have any RoR examples at this time - others here may be able to help, but it's essentially a SOAP webservice, with the SimpleAPI using less complex data types than the standard version. The standard API already lets you send postcards and letters, but is more complex to use from some environments due to it's complex data types.
The test version of Docmail's SimpleAPI has now been updated to expose postcard calls to allow physical postcards to be send via the Simple version of the API. Once we're happy with the updates, we'll make them available in the live version too.
Although you've probably already been through the other info on the API, here are some links/addresses in case anyone else needs them:
Docmail API Info Page
Simple API Test Webservice & Website (for the Simple API Live versions, replace "Test" with "Live"):
https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?WSDL
https://www.cfhdocmail.com/Test
Hope that helps.
Will
(from Docmail)

Related

How to pass form data to an external API in ROR

Hello I am designing an online application that uses mobile money as a means of payment. But I need assistance on how I can pass my order form data to the API of the mobile money service providers who complete the transaction.
Try httparty, post method.
An existed example could be
options = {:type => auto}
payload = options.to_json
query = {
:request_id => request_id,
......................
:user_id => user
}
response = post("/tbc/submit_job.json", :body => payload, :query => query)
You can use httparty to customize yours.

Accessing Pingdom API with HTTParty from Rails

Hi there i have a problem while accessing Pingdom API from my rails app. Here is the code:
auth = {:username => pingdom_username, :password => pingdom_password, :key => application_key }
response =HTTParty.get("https://api.pingdom.com/api/2.0/checks", :basic_auth => auth)
I have tried in many ways (putting the app key as a separate header, having different names :key, :app_key, :api_key) but i always receive error as a mistake with the application key:
so,
puts response.body
returns:
{"error":{"statuscode":403,"statusdesc":"Forbidden","errormessage":"Missing application key. Please see the documentation."}}
Any Ideas what am I doing Wrong? Thank you in advance
I found my misstake :) THe key should be provided as an HTTP header
One way can be:
response = HTTParty.get("https://api.pingdom.com/api/2.0/checks", :basic_auth => auth, :headers => {"App-Key" => application_key})
the other way is creating a class where you set the parameters and than you call get through this class.
class Pingdom
include HTTParty
headers "App-Key" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxm6ogjzpd7v"
end
response = Pingdom.get("https://api.pingdom.com/api/2.0/checks", :basic_auth => auth)

Create record example for Quickbooks Online and Intuit Anywhere using Ruby and httparty?

Can someone post an example of creating a record in quickbooks online / intuit anywhere, using ruby and httparty?
I am working on an integration to a ruby on rails app using intuit anywhere, and am running into an issue with my POST request when attempting to create a new record. I have been able to successfully retrieve data (customers) using a POST command that doesn't require XML data in the body of the request, but am running into trouble when trying to create new records that have required fields that need to be passed in XML in the body of the request.
I get the same flavor of error in any entity for which I try to create a record for: an invalid or missing required field. It seems to me that the XML in the body (where the data for the required fields is added) is either being ignored (incorrect formatting?) or is not being attached.
I was hoping the someone else familiar with ruby could post an example of a record creation using httparty. If I could see how to correctly pass the XML using httparty, I can fix my problem myself.
I have been using the customer.com example (https://code.intuit.com/integration/viewvc/viewvc.cgi/IntuitAnywhere-Ruby/customer.com/?root=intuitanywhere&system=exsy1003) mostly as posted, with a few irrelevant modifications needed to get it to work in Rails 3.1. I am using the data pull and handling provided in the example, which looks like a pretty standard API wrapper built using httparty.
I am using a pull similar to the one found in the company_controller customers method. Here are two different ways I have tried submitting the XML:
#########################################
#Example 1 - XML
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}",
{ :body =>
"<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\">
<Name>Test Account 2</Name>
<Desc>Test Account</Desc>
<Subtype>Savings</Subtype>
<AcctNum>5001</AcctNum>
<OpeningBalanceDate>2010-05-14</OpeningBalanceDate>
</Account>",
:headers => {
"Content-Type" => "application/xml"
}}
)
#########################################
#Example 2 - hash
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}",
{ :body => {
:Account => {
:Name => "Loan Account 2",
:Desc => "Loac Account 2",
:Subtype => "Savings",
:AcctNum => "5001",
:OpeningBalanceDate => "2011-04-22"
}
},
:headers => {
"Content-Type" => "application/xml"
}}
)
I incorrectly assumed the customer.com example provided by intuit was using the httparty gem to make the POST call, so I was using the wrong syntax. They are actually using the OAuth gem's POST call, who's syntax can be found here: http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html
I also had to modify the headers to get the Intuit Anywhere service to accept the XML body. Here is the code that finally worked for me to create a record in quickbooks online using intuit anywhere:
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}", "<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\"><Name>Test Account </Name><Desc>Test Account</Desc><Subtype>Savings</Subtype><AcctNum>5002</AcctNum><OpeningBalanceDate>2010-05-14</OpeningBalanceDate></Account>", {"Content-Type" => "application/xml", "standalone" => "yes", "encoding" => "UTF-8"})

mini fb posting to friend's wall using graph api

Hi I have read all the other post relating to this but I think I am missing something fundamental. I am using mini_fb in my ruby on rails application for handling the facebook api. I have the following code:
current_user.session.post('me', :type => :feed, :params => {:name => "name",
:to => "{\"data\":[{\"name\":\"#{friend.facebook_name}\",\"id\":\"#{friend.facebook_id}\"}]}",
:link => url_of_app,
:description => "desc",
:actions => "{\"name\": \"action name\", \"link\": \"url\"}"})
The above posts to the current user's wall with or without the "to" parameter set. Everything works, except for the "to" parameter. I have read the graph post to wall over and over again and I can't figure out what is wrong with this code of mine. I would really appreciate it if someone could point out my mistake.
I've never used ruby's version, but probably the problem is in the first parameter. You are targeting 'me' feed, while should be targeting your friends feed. Try fetching your friend id and doing something like
current_user.session.post(friend.facebook_id, :type => :feed, :params => ...)
Wow, mini_fb looks so verbose :)
Telémako is right, you need to use your friends id. I give you another alternative for more nice code. Use Koala.
https://github.com/arsduo/koala/wiki/Graph-API
#graph.put_wall_post("explodingdog!", {:name => "i love loving you", :link => "http://www.explodingdog.com/title/ilovelovingyou.html"}, "tmiley")
=> {"id"=>"83901496_520908898070"}
I use it in my projects and works very well.

403 Error when Authenticating using tumblr gem for rails application

I have a ruby-on-rails application that wishes to utilise the tumblr gem for adding posts when an action is taken (eg: creating a blog post)
I currently have the tumblr gem installed and can manage to fetch my posts using
#tumblruser = Tumblr::User.new('myemail','mypassword')
However when i go to add a post where it asks me to pass the user information like so (according to the API for the gem)
post = Tumblr::Post.create(#tumblruser, :type => 'video', :embed => #post.video_html, :title => #post.title, :caption => #post.content)
it just does not want to authenticate and returns a 403 error
anyone had any experience with this?
NEW SOLUTION:
I have found recently that there has been a problem with the gem. So I have made a copy of it, changed a few things in the docs and code and put it at http://rubygems.org/gems/matenia-tumblr-api
Hope the changes and docs help someone else out there.
As always I welcome any improvements, or refactoring on any of my projects.
Kind Regards,
Matenia
OLD ANSWER BELOW
I managed to get around this by the way ... all i did was declare the username and password in place of #tumblruser like so:
post = Tumblr::Post.create(:email => 'user name email here',
:password => 'my password',
:type => 'video',
:embed => #post.video_html,
:caption => #postcontent)
where #postcontent is the html text of post.content and gsubbed to escape most of the html.
hope this saves someone else some time.
If you are only going to check authentication with any media like Facebook , Twitter ,LinkedIn ,Tumblr , Github and almost 20 others (you can check Here ) .Then omniauth gem is the first thing that comes to mind . Means It's clearly simplest solution for authentication and I love it

Resources