I'm trying to find some samples in Prestashop API where I can:
Get orders
For each order, get its details
I'm trying to implement an integration but couldn't find a simple way to do that in Ruby
You can use HTTParty:
require 'httparty'
SITE_URL= 'http://example.com'
WEB_SERVICE_KEY = 'EXAMPLE'
response = HTTParty.get "#{SITE_URL}/api/orders?display=full", basic_auth: {username: WEB_SERVICE_KEY }
orders = response['prestashop']['orders']
Related
I'm new to Ruby and trying to use the Ruby gem 'rest-client' to access the REST API of my accounting system, e-conomic.com. I am able to connect via tokens and e.g. fetch customer details - so far, so good.
However, I'm struggling to figure out how to POST and thus create a new customer entry with e.g. address, name, mail etc.. In particular, I'm looking to get the code to both include my authentication token details (i.e. content of hHeader below), while also including a payload of customer details.
Details about the customer creation via the REST API:
https://restdocs.e-conomic.com/#post-customer-groups
Details about the rest-client ruby gem:
https://github.com/rest-client/rest-client
I'm running Ruby 2.3.3 on Windows 7 in the Atom editor.
My code is as below:
Dir.chdir 'C:\Ruby23\bin'
require 'rest-client'
require 'rconomic'
require 'json'
hHeader = {"X-AppSecretToken" => 'tokenID1_sanitized', "X-AgreementGrantToken" => 'tokenID2_sanitized', "Content-Type" => 'application/json'}
hCustomer = RestClient.get("https://restapi.e-conomic.com/customers/5", hHeader) # => creates a response showing customer 5 (shown for example of GET)
Your input would be much appreciated!
Martin
You put the wrong api doc, it's POST customer, not POST customer-groups. You should send the post with:
body = {'address' => 'Example Street', 'name' => 'John Doe'}.to_json
RestClient.post "https://restapi.e-conomic.com/customers/", body, hHeader)
I am working on a shopify app in which I want to run a script which is in Ruby. I want to update the 'position' and 'sort_value' of Collect object as per this link https://docs.shopify.com/api/collect. Everytime I try to do so I got an ActiveResource Error.
Here is my code in irb:
require 'shopify'
require 'active_resource'
shop_url = "https://#{API_KEY}:{PASSWORD}#SHOP_NAME.myshopify.com/admin"
ShopifyAPI::Base.site = shop_url
product = ShopifyAPI::Collect.find(:id)
product.position = 4
product.save
I have tried the code given below, which works fine in irb
product = ShopifyAPI::Product.find(179761209)
product.handle = "burton-snowboard"
product.save
I got this error:
ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found
Can we send http PUT request on Collect object to update position? Thanks in Advance..
It appears you are not providing any ID to your call.
product = ShopifyAPI::Collect.find(:id)
What is that supposed to return?
I think you have a 404 returned it is a good indication you are not asking for something with a valid ID. Your second call works fine with an ID.
Im trying to make an app which would iterate through my own posts and get a list of users who favorited a post. Afterwards I would like the application to follow each of those users if I am not already following them. I am using Ruby for this.
This is my code now:
#client = Twitter::REST::Client.new(config)
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
user = #client.user()
tweets = #client.user_timeline(user).take(20)
num_of_tweets = tweets.length
puts "tweets found: #{tweets.length}"
tweets.each do |item|
puts "#{ item}" #iterating through my posts here
end
any suggestions?
That information isn't exposed in the Twitter API, either through a timeline collection or via the endpoint representing a single tweet. This'll be why the twitter gem, which provides a useable interface around the Rest API, cannot give you what you're after.
Third party sites such as Favstar do display that information, but as far as I know their own API does not expose the relevant users in any manageable way.
https://github.com/fullcontact/fullcontact-api-ruby
I'm trying to use the FullContact API Wrapper for Ruby (it's a gem) instead of the pure REST API. I'm trying to figure out how to grab the person's profile pictures from email address. I know how to get them from the REST API that responds with JSON, but not sure what the example code there is doing.
person = FullContact.person(email: "brawest#gmail.com") (pulled from example in the Github linked)
So now how do I retrieve profile pictures from person? What data type is it storing?
The FullContact gem uses Hashie, and from a call it returns a Hashie::Rash object.
So if you were trying to access photos:
> person = FullContact.person(email: "email")
=> [#<Hashie::Rash contact_info=#<Hashie::Rash family_name=...
> person.photos
=> [#<Hashie::Rash is_primary=true type="facebook" type_id="facebook" type_name="Facebook"...
Hope that helps!
I am trying to use ruby and Mechanize to parse data on foursquare's website. Here is my code:
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
page = agent.get('https://foursquare.com')
page = agent.click page.link_with(:text => /Log In/)
form = page.forms[1]
form.F12778070592981DXGWJ = ARGV[0]
form.F1277807059296KSFTWQ = ARGV[1]
page = form.submit form.buttons.first
puts page.body
But then, when I run this code, the following error poped up:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mechanize-2.0.1/lib/mechanize/form.rb:162:in
`method_missing': undefined method `F12778070592981DXGWJ='
for #<Mechanize::Form:0x2b31f70> (NoMethodError)
from four.rb:10:in `<main>'
I checked and found that these two variables for the form object "F12778070592981DXGWJ" and "F1277807059296KSFTWQ" are changing every time when I try to open foursquare's webpage.
Does any one have the same problem before? your variables change every time you try to open a webpage? How should I solve this problem?
Our project is about parsing the data on foursquare. So I need to be able to login first.
Mechanize is useful for sites which don't expose an API, but Foursquare has an established REST API already. I'd recommend using one of the Ruby libraries, perhaps foursquare2. These libraries abstract away things like authentication, so you just have to register your app and use the provided keys.
Instead of indexing the form fields by their name, just index them by their order. That way you don't have to worry about the name that changes on each request:
form.fields[0].value = ARGV[0]
form.fields[1].value = ARGV[1]
...
However like dwhalen said, using the REST API is probably a much better way. That's why it's there.