Class: BuyonApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/buyon_api/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



4
5
6
# File 'lib/buyon_api/client.rb', line 4

def initialize
  @conn = BuyonApi::Api.call
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/buyon_api/client.rb', line 8

def method_missing(m, args, &block)
  result = @conn.post do |req|
    req.url m.to_s
    req.headers['Content-Type'] = 'application/json'
    req.params = args
  end

  obj_hash JSON.parse(result.body)
end

Instance Method Details

#obj_hash(result) ⇒ Object



18
19
20
# File 'lib/buyon_api/client.rb', line 18

def obj_hash(result)
  OpenStruct.new(result)
end