How to call api using savon gem - ruby-on-rails

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

Related

Consuming webhooks shopify-api

I'm in the process of building my first RoR webapp and I'm currently trying to set up an integration with Shopify. I want to create an order in my web application whenever one is created in Shopify. For this I want to use a Shopify webhook. Step two will be to set it up so that after processing the order I'll use the Shopify API to update some records. For now my main concern is receiving the webhooks. I've been looking at the documentation for the Shopify gem but with my limited RoR skills I can't seem to figure it out. I've been searching the web for a few hours but can't find any clear examples / explanation.
I'm confused about this gem; shopify-api (https://docs.shopify.com/api/authentication/using-api-gem-with-private-app-credentials). I've created a private app in shopify, but after that I'm lost. Where am I supposed to place this code and how is this invoked after receiving a webhook?
It seems to me that this gem is mainly used to access the Shopify API instead of consuming webhooks. Am I going at this all wrong?
For receiving the changes (especially Order Creation event) from Shopify, you don't need to use any gem or third party to integrate!
Here are the steps that I did before in my app:
1. Provide an api in your app to receive a webhook event
Here is an example:
Your route:
post '/shopify/create_order', to: 'shopify#create_order'
Your controller:
class ShopifyController < ApplicationController
def create_order
# process shopify order here: all info in `params`
end
end
2. Config to call webhook from your Shopify Settings. The configured url will be:
http://your_production_url/shopify/create_order
If you want to test from localhost, go to step 3
3. (Optional) Test from your localhost
Download this free tool: ngrok and extract it to your machine.
Run ngrok in your terminal to generate a forwarding url to your localhost by this command:
ngrok http 3000
So you will get the output from console like this:
Copy the generated url (http://fbc5cf88.ngrok.io for example) above and add to your Shopify settings in step 2
4. (Optional but critical) Set privacy in your app, to make sure only Shopify can call your api. Follow this documentation
Shopify also provides api to integrate with Shopify resources: create/update product, collection, collect, metafield,... You can directly use it. All was described at Shopify API documentation. But the easiest way to work with Shopify is shopify_api gem which provides an interface to work with Shopify (via ActiceResource)
Probably reading up on the documentation on Webhooks would help you figure out a lot of what you need to do
In essence, here are the overview of what you need to start consuming web hooks:
1. Create your web hooks
You can do it using the Shopify API (POST /admin/webhooks.json)
Or you can do it through store admin
The params that you need to take note of:
topic: the type of hook you want (for e.g orders/create)
address: the URL of the endpoint that you would be consuming the hook at (for e.g: https://myapp.domain.com/hooks/order_create)
2. Create your endpoint that will respond to hooks
You then need to setup your ROR app to expose an endpoint that will respond to a POST request.
This endpoint is the same URL that you previously specified when creating the hook
More info at https://docs.shopify.com/api/webhooks/using-webhooks#respond-to-webhook
Notes: You also need to implement a way to verify that requests that you receive through the endpoints came from Shopify, detailed here.

Shopify Webhook Setup With Rails

I'm trying to setup a basic shopify webhook app with order/create in Rails.
I have followed the instructions in the support api for webhooks and deployed the Sync_App_Demo example provided there but cannot get to authorise log in authorize step. It brings up the 'We're sorry something went wrong' page - myapp/login/authenticate
I'm new to webhooks and have looked all over SO and googled but had no joy working out the basic set up for the webhook connection. I placed the shopify app api key and secret in the based on the shopify_app gem setup which is created but not sure if this is correct.
Also once I do get connnected via a webhook controller where abouts do point (eg. what url /order.xml in the order notifcations panel of my test shop) the webhook order/create?
Any help would be much appreciated.
Here is the link to the shopify sync app demo:
https://github.com/Shopify/sync_app_demo
http://wiki.shopify.com/WebHook#Rails
Stumbled upon your question when searching for how to do this myself. Given that it's been more than a few years since you posted this here, hopefully you've already found the answer. If you haven't, here's what we did:
In both cases, you'll have to know your Shopify API key, password, and store name.
1) Using Shopify's shopify_api gem:
new_webhook = ShopifyAPI::Webhook.new({
topic: "orders/create",
address: "http://www.example.com/webhook", # substitute url with your endpoint
format: "json"
})
new_webhook.save
2) Using terminal:
curl -X POST -H 'Content-Type: application/json' 'https://shopify_api_key:shopify_api_password#store_name.myshopify.com/admin/webhooks.json' -d '{"webhooks": {"topic": "orders\/create", "address": "http:\/\/www.example.com\/webhook", "format": "json"}}'
You so you'll need to add in your own shopify_api_key, shopify_api_password, store_name, and address endpoint that you want to receive the published events.
Other useful things:
Ultrahook - for receiving webhooks on locally run server (eg. when using rails s)
RequestBin - for seeing webhook responses raw body and headers
For new people getting started with Shopify App development with Ruby on Rails, I strongly suggest using the shopify_app gem that includes the shopify_api gem.
To register a webhook, you can run the add_webhook generator or add a line manually in the shopify_app.rb initializer:
config.webhooks = [
{topic: 'app/uninstalled', address: 'https://myapp.url/webhooks/app_uninstalled', format: 'json'},
{topic: 'orders/create', address: 'https://myapp.url/webhooks/orders_create', format: 'json'},
]
With this setup, your app will register the webhooks on application install.

upgrade from Google Local API V1.0.3 to Google Map API

How can we upgrade from Google Local API V1.0.3 to Google Map API in our rails application.
Also what are the other better plugins to use like YM4R/GM.
Rails 2.3.4
Ruby 1.8.7
I'm using google_places gem google_places, gem simply allows an easy interface to send the required HTTP requests and parse the JSON output into ruby hashes.
#client = GooglePlaces::Client.new("API_KEY")
#spot_list = #client.spots(-33.8670522, 151.1957362, :types => 'restaurant')
This hits https://maps.googleapis.com/maps/api/place/search/json url.
Check The Google Places API for other options which can be passed as search parameters.
parse through #spot_list and take out the reference of each place returned in response. Now, #client.spot "reference" will gives the details of the business.
In this case https://maps.googleapis.com/maps/api/place/details/json is accessed to get the data

Sending SMS messages from a Rails Application without Gems

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

Rails - Sending XML or JSON

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).

Resources