Class: MagentoClient

Inherits:
Object
  • Object
show all
Includes:
Handshake
Defined in:
lib/magento_client.rb,
lib/magento_client/version.rb,
lib/magento_client/handshake.rb

Defined Under Namespace

Modules: Handshake

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Methods included from Handshake

#get_verifier_code

Constructor Details

#initialize(config = {}) ⇒ MagentoClient

Returns a new instance of MagentoClient.



13
14
15
# File 'lib/magento_client.rb', line 13

def initialize(config = {})
  @config = OpenStruct.new(config)
end

Instance Method Details

#access_tokenObject



21
22
23
24
25
26
# File 'lib/magento_client.rb', line 21

def access_token
  return @access_token if @access_token

  code = get_verifier_code
  @access_token = request_token.get_access_token(:oauth_verifier => code)
end

#consumerObject



32
33
34
35
36
37
38
39
40
# File 'lib/magento_client.rb', line 32

def consumer
  @consumer ||= OAuth::Consumer.new(@config.key, @config.secret,
    :site => @config.url,
    :request_token_path => "/index.php/oauth/initiate",
    :authorize_path => "/index.php/admin/oauth_authorize",
    :access_token_path => "/index.php/oauth/token",
    :http_method => :get
  )
end

#get(params) ⇒ Object



17
18
19
# File 'lib/magento_client.rb', line 17

def get(params)
  MultiJson.load(access_token.get(params).body)
end

#request_tokenObject



28
29
30
# File 'lib/magento_client.rb', line 28

def request_token
  @request_token ||= consumer.get_request_token
end

#resetObject



42
43
44
# File 'lib/magento_client.rb', line 42

def reset
  @consumer = @request_token = nil
end