Class: Zoho::Inventory::API

Inherits:
Object
  • Object
show all
Defined in:
lib/zoho/inventory/api.rb

Constant Summary collapse

BASE_URI =
'https://inventory.zoho.com/api/v1/'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:) ⇒ API

Returns a new instance of API.



11
12
13
# File 'lib/zoho/inventory/api.rb', line 11

def initialize(type:)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/zoho/inventory/api.rb', line 9

def type
  @type
end

Instance Method Details

#construct_uri(path = '') ⇒ Object



15
16
17
# File 'lib/zoho/inventory/api.rb', line 15

def construct_uri(path = '')
  URI.parse("#{BASE_URI}#{type}#{path}#{config_uri}")
end

#default_optionsObject



29
30
31
# File 'lib/zoho/inventory/api.rb', line 29

def default_options
  { page: 1, per_page: Zoho.configuration.per_page }
end

#merge_options(options = {}) ⇒ Object



25
26
27
# File 'lib/zoho/inventory/api.rb', line 25

def merge_options(options = {})
  options.map { |key, value| "#{key}=#{value}" }.join('&')
end

#request(uri, method, params = {}) ⇒ Object



19
20
21
22
23
# File 'lib/zoho/inventory/api.rb', line 19

def request(uri, method, params = {})
  response = HTTParty.send(method, uri, params)

  parse_result(response)
end