What are the links/keys needed to create a ruby application to send an SMS using an API. Without having to write gems for it? I have a link to the service and an API key. I need to know where to start. Im new to ruby and am trying to follow this tutorial but cant seem to get anywhere without knowing what i do without using clickatell. http://lukeredpath.co.uk/blog/sending-sms-messages-from-your-rails-application.html
For sending the actual HTTP request, you can use one of the several ruby HTTP libraries/gems, like REST Client, httparty or plain Net/HTTP.
The most simple one might be REST Client, example:
require 'rest_client'
API_URL = 'http://yourapiurl.com/resource'
API_KEY = 'thatoneapikey'
RestClient.post API_URL, :api_key => API_KEY, :number => '7812637813', :body => 'Foo SMS Text Bar Baz'
Best regards
Tobias
There is a gem done by a friend for the routo messaging system
https://github.com/weboglobin/Routo
you can use it, or just take it as an inspiration
Related
I am using savon gem in my rails application for calling service_now api. I want to call the api for update description. I have url for updating
https://servicenow.com/xyzlist?JSONv2&sysparm_query=number='xyz123'&sysparm_action=update&displayvalue=true
body "comments":"updated description"
Above is working perfectly in postmen. But how can i pass this params into my local rails application for updating
I am using below code for creating tickets.
client = Savon.client(wsdl: "https://servicenow.com/xyzlist.do?WSDL",basic_auth: ['xyz', 'abc'], log: true, log_level: :debug, pretty_print_xml: true)
response = client.call(:insert, message: params)
Can you please anyone help me for this issue.
You are referring to two different APIs in your example code: JSONv2 and SOAP.
Two questions: 1) do you need to use SOAP, or can you use REST instead? (Rails should support this without issue) and 2) what version of ServiceNow are you using? If you're running Geneva or later and you're able to use REST, you should be using the REST Table API for new integrations, not JSONv2.
See the documentation here for examples:
https://developer.servicenow.com/app.do#!/rest_api_doc?v=istanbul&id=r_TableAPI-PUT
In one web service written in Rails, I would like to answer with a file along with additional information.
For this, I consider respond with multipart data. How can I send a multipart response with a file and json?
If there is a better way to do this, please let me know. Note that is not possible add the extra data in the file I'm sending.
Extra points for the face of the problem, that is send a file and data at same time. I already accomplished that by doing a multipart request, but if is there a better way to do this, I would like to know.
I don't know exactly what kind of front end you are using and what your browser compatibility requirements are, or you need the webservice for integration with other apps only, but assuming you are communicating with server over ajax and your app is running in modern browser (or you are allowed to use flash plugin), you can return file contents as base64 encoded string as a part of json response. So in rails controller you would have something like this:
render json: {success: true, file: {name: 'invoice.pdf', data: Base64.encode64(#file.read), extra_info: 'some info'}}
on client side you can process that json, get all the metadata you need from it and also let user save the file to their computer. For that you can use flash plugin or native api implementation
This way you can return couple files with any metadata you want with them to user and on client side user can save files if needed. Also, same webservice can be consumed by other applications as long as they can parse json.
try using gem 'curb' or 'rest-client' gem.
https://github.com/rest-client/rest-client
and
https://github.com/taf2/curb
I'm sure you have done some googling already, have you seen this already? It seems like there is a Gem for what you are trying to accomplish, the Gem however seems to be pretty old.
Scenario:
I'm a registered user of a site(a rails app).
I have my contacts in linked in whom I would like to invite to see this app(it would be followed up with their registration into this app).
For this , I would be sending them a message with a subject and body.
Rays of Hope:
I need to make use of the messaging api of linkedin and make it talk with my rails app. I can't use the connections api of linked in to retrieve the email addresses as basically any of the linkedin api's don't expose my(the registered user of linked in) contacts email.
To talk with the connections api in my rails app, I was making use of the linkedin gem. It doesn't look like this gem as of now has support for the messaging api of linkedin.
Finally:
Any ideas where can I get started on this..?. I'm kinda clueless as I have never played around with api's directly, ..yet..:).
I'm on Ubuntu 10.04 OS.
Thank you
I had the same problem with the gem lacking messaging functionality. By using the existing code as a reference, I threw this code in an initializer file (config/initializer) and it worked. Give it a try.
LinkedIn::Client.class_eval do
# options should be a hash like this:
# options = {:recipients => {:values => [:person => {:_path => "/people/~" }, :person => {:_path => "/people/USER_ID"} ]}, :subject => "Something",:body => "To read" }
def send_message(options)
path = "/people/~/mailbox"
post(path, options.to_json, "Content-Type" => "application/json")
end
end
This might not exactly answer the question, but could be of some help..
Have you looked here:
https://github.com/pengwynn/linkedin/blob/master/lib/linked_in/api/update_methods.rb
If you'll log an issue on the project repo and include some code, the
whole community can try to help:
https://github.com/pengwynn/linkedin/issues
This was provided by Wynn Netherland on contacting him. Credit goes to him..:)
I'm new to Rails and trying to send a request to Chargify to cancel a subscription. Their API says I need to send the method DELETE to a xml URL. This isn't a Chargify based question but rather... how would I have a user click a button that then generates this request and sends it within my Rails app? You can view this url to see what I"m trying to do - http://docs.chargify.com/api-subscriptions#cancel. Also it's working fine when I run a command-line test so I know my code works, just now sure how to put it into my Rails app (view/controller). Thanks
Something like this should work using Net::HTTP in the Ruby Standard Library:
require 'net/http'
http = Net::HTTP.new('subdomain.chargify.com')
request = Net::HTTP::Delete.new('/subscriptions/1337.xml')
response = http.request(request)
You could include it in your controller's method, but unless you need to make sure the request finished before you send a response back, I recommend making the request to Chargify in a background job. Check out the delayed_job or resque libraries.
You probably want to use the Net::HTTP library. Also, checkout the source of some other ruby API bindings on Github to see how they use and structure this type of behavior (specifically, Twilio, Dropbox, and Flickraw).
Is there a way to mock out Curb's Easy.perform method for unit testing? I use this to hit Facebook's graph API, and none of the http mock libs seem to support Curb.
What's the best approach here?
WebMock has recently added Curb support. :)
http://github.com/bblimke/webmock
I really think fakeWeb is a great way to fake out network calls; Whatever HTTP library you use, you'll just specify what response text and code you want to receive.
Described as:
FakeWeb is a helper for faking web
requests in Ruby. It works at a global
level, without modifying code or
writing extensive stubs
Example from the github repository:
FakeWeb.register_uri(:get, "http://example.com/test1", :string => "Hello World!")
Net::HTTP.get(URI.parse("http://example.com/test1"))
=> "Hello World!"
Net::HTTP.get(URI.parse("http://example.com/test2"))
=> FakeWeb is bypassed and the response from a real request is returned