0

This is my curl command which works nicely in Command line :

curl --data @order_new.json \
     -H "X-Augury-Token:My_token_goes_here" \
     -H "Content-Type:application/json" \
     http://staging.hub.spreecommerce.com/api/stores/store_id_goes_here/messages

I need to implement the same in rails using any sort of Gem, Tried with HTTParty /rest_client / spree-api-client, but something wrong here :

require 'httparty'

result = HTTParty.post(
        "http://staging.hub.spreecommerce.com/api/stores/52eb347f755b1c97e900001e/messages",
        :body => JSON.parse(File.read("order_new.json")),
        :header => {
           "X-Augury-Token" => "UjjKsdxbrwjpAPx9Hiw4",
           "Content-Type" => "application/json" 
        }
)

But I am getting Error,

"The page you were looking for doesn't exist (404)"

I need rails equivalent of above curl command, use of spree-api-client gem will be much helpful.

Ajay
  • 4,199
  • 4
  • 27
  • 47

2 Answers2

0

If you prefer to use the Spree::API::Client, could you post the results of your findings? Could you evaluate the output of the following commands and post back:

client = Spree::API::Client.new('http://staging.hub.spreecommerce.com/api/', 'UjjKsdxbrwjpAPx9Hiw4')
client.products.inspect
Jaap Haagmans
  • 6,232
  • 1
  • 25
  • 30
  • I have already seen such in github link, But how I can pass the -header, -data attributes just like curl is doing. – Ajay Feb 06 '14 at 09:23
  • You shouldn't need to. This gem is not a replacement for the curl command, it's a client that you can use to communicate with spree. If you're trying to create an order, you should be able to do that with `client.create_order(data)`. Take a look at the code to understand what is happening: https://github.com/andrew/spree-api-client/blob/master/lib/spree-api-client.rb, https://github.com/andrew/spree-api-client/blob/master/lib/spree-api-client/connection.rb and https://github.com/andrew/spree-api-client/blob/master/lib/spree-api-client/orders.rb – Jaap Haagmans Feb 06 '14 at 09:37
  • Yes, I got your point, using client.create_order(data), we can create_order in our store front (spree), but it does not pass any message to hub explicitly. but as per my question, I need to pass similar notification message to my hub (staging.hub.spreecommerce.com/) ! :) – Ajay Feb 06 '14 at 12:29
  • Ah, I'm sorry. I'm unfamiliar with the Spreecommerce hub, but I've looked into it. Isn't this simply what you're looking for? https://github.com/spree/spree_hub_connector – Jaap Haagmans Feb 06 '14 at 13:44
0
require 'httparty'

result = HTTParty.post(
        "http://staging.hub.spreecommerce.com/api/stores/52eb347f755b1c97e900001e/messages",
        :body => @order.to_json,
        :header => {
           "X-Augury-Token" => "UjjKsdxbrwjpAPx9Hiw4",
           "Content-Type" => "application/json" 
        }
)

Don't parse json while passing to HTTParty body

Anil Maurya
  • 2,298
  • 1
  • 22
  • 28
  • GOT ERROR: NoMethodError: undefined method `json' for nil:NilClass Let's forget about adding .json file as input, Can We pass an object in :body section ? Just like :body => Order.last ? – Ajay Feb 06 '14 at 12:25
  • you have to pass json in body , so load order in \@order and write \@order.to_json – Anil Maurya Feb 06 '14 at 12:34