Class: MagentoRestApi::Connection
- Inherits:
-
Object
- Object
- MagentoRestApi::Connection
- Defined in:
- lib/magento_rest_api.rb
Overview
This Gem will enable you to communicate to the rest api of magento 1.9.x You first need to authenticate this app to your magento by running the command % authenticate
Example:
% irb
>> require 'restfull_oauth'
>> service = RestfullOauth::Connection.new({"consumer_key"=>"your_consumer_key", "consumer_secret"=>"your_consumer_secret", "token"=>"your_token", "token_secret"=>"your_token_secret"})
>> post_data = {'foo' => 'bar' }.to_json
>> response = MagentoRestApi::connect('POST','https://your magento server/api/rest/products/200', post_data)
=> #<Net::HTTPOK 200 OK readbody=true>
>> puts JSON.parse(response.body).to_yaml
Instance Method Summary collapse
- #connect(method, uri, post_data = nil) ⇒ Object
-
#initialize(config = {}) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(config = {}) ⇒ Connection
Returns a new instance of Connection.
27 28 29 30 |
# File 'lib/magento_rest_api.rb', line 27 def initialize(config = {}) @config = config self end |
Instance Method Details
#connect(method, uri, post_data = nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/magento_rest_api.rb', line 32 def connect(method, uri, post_data=nil) params = params(@config['consumer_key'], @config['token'] ) signature_base_string = signature_base_string(method, uri.to_s, params) signing_key = @config['consumer_secret'] + '&' + @config['token_secret'] params['oauth_signature'] = url_encode(sign(signing_key, signature_base_string)) header_string = create_header(params) json_response = request_data(header_string, uri, method, post_data) end |