Class: Xsys::Api

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

Class Method Summary collapse

Class Method Details

.add_background_job_event(code, event_description) ⇒ Object



23
24
25
26
# File 'lib/xsys/api.rb', line 23

def self.add_background_job_event(code, event_description)
  params = { description: event_description }
  Model::JobEvent.new(post_request("/background_jobs/#{code}/job_events", params)[:body])
end

.configure(args = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/xsys/api.rb', line 3

def self.configure(args={})
  if args[:endpoint].present?
    @endpoint = "#{args[:endpoint]}/api"
  else
    @endpoint = "https://gestion.lhconfort.com.ar/api"
  end

  @access_token = args[:access_token]

  self
end

.get_background_job(code) ⇒ Object



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

def self.get_background_job(code)
  Model::BackgroundJob.new(get_request("/background_jobs/#{code}")[:body])
end

.get_price_lists(filters = {}) ⇒ Object



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

def self.get_price_lists(filters={})
  get_request('/price_lists')[:body].map { |r| Model::PriceList.new(r) }
end

.get_product(product_id) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/xsys/api.rb', line 51

def self.get_product(product_id)
  response_body = get_request("/products/#{product_id}")[:body]

  if response_body == 'null'
    nil
  else
    Model::Product.new(response_body)
  end
end

.get_product_categories(filters = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/xsys/api.rb', line 78

def self.get_product_categories(filters={})
  response = get_request('/product_categories', filters)

  if response[:headers][:link]
    {
      pagination: Pagination.new(JSON.parse(response[:headers][:link])),
      results: response[:body].map { |r| Model::ProductCategory.new(r) }
    }
  else
    response[:body].map { |r| Model::ProductCategory.new(r) }
  end
end

.get_product_category(category_id) ⇒ Object



91
92
93
# File 'lib/xsys/api.rb', line 91

def self.get_product_category(category_id)
  Model::ProductCategory.new(get_request("/product_categories/#{category_id}")[:body])
end

.get_product_price_lists(filters = {}) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/xsys/api.rb', line 95

def self.get_product_price_lists(filters={})
  response = get_request('/product_price_lists', filters)

  if response[:headers][:link]
    {
      pagination: Pagination.new(JSON.parse(response[:headers][:link])),
      results: response[:body].map { |r| Model::ProductPriceList.new(r) }
    }
  else
    response[:body].map { |r| Model::ProductPriceList.new(r) }
  end
end

.get_product_provider(provider_id) ⇒ Object



74
75
76
# File 'lib/xsys/api.rb', line 74

def self.get_product_provider(provider_id)
  Model::ProductProvider.new(get_request("/product_providers/#{provider_id}")[:body])
end

.get_product_providers(filters = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/xsys/api.rb', line 61

def self.get_product_providers(filters={})
  response = get_request('/product_providers', filters)

  if response[:headers][:link]
    {
      pagination: Pagination.new(JSON.parse(response[:headers][:link])),
      results: response[:body].map { |r| Model::ProductProvider.new(r) }
    }
  else
    response[:body].map { |r| Model::ProductProvider.new(r) }
  end
end

.get_sale(code) ⇒ Object



138
139
140
141
142
143
144
145
146
# File 'lib/xsys/api.rb', line 138

def self.get_sale(code)
  response_body = get_request("/sales/#{code}")[:body]

  if response_body == 'null'
    nil
  else
    Model::Sale.new(response_body)
  end
end

.get_sellersObject



108
109
110
# File 'lib/xsys/api.rb', line 108

def self.get_sellers
  get_request('/sellers')[:body].map { |r| Model::Seller.new(r) }
end

.get_shops(kind = nil) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/xsys/api.rb', line 112

def self.get_shops(kind=nil)
  shop_kinds = [:commercial, :virtual, :physical, :stockable, :service, :with_target]

  if kind.nil?
    get_request('/shops')[:body].map { |r| Model::Shop.new(r) }
  elsif shop_kinds.include?(kind.to_sym)
    get_request("/shops/#{kind}")[:body].map { |r| Model::Shop.new(r) }
  else
    []
  end
end

.search_product_ids(filters = {}) ⇒ Object



45
46
47
48
49
# File 'lib/xsys/api.rb', line 45

def self.search_product_ids(filters={})
  response = get_request('/product_ids', filters)

  response[:body]['product_ids']
end

.search_products(filters = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xsys/api.rb', line 32

def self.search_products(filters={})
  response = get_request('/products', filters)

  if response[:headers][:link]
    {
      pagination: Pagination.new(JSON.parse(response[:headers][:link])),
      results: response[:body].map { |r| Model::Product.new(r) }
    }
  else
    response[:body].map { |r| Model::Product.new(r) }
  end
end

.update_background_job(code, params) ⇒ Object



19
20
21
# File 'lib/xsys/api.rb', line 19

def self.update_background_job(code, params)
  Model::BackgroundJob.new(put_request("/background_jobs/#{code}", params)[:body])
end

.update_cash_withdrawal_items(shop_code, cash_withdrawal_items) ⇒ Object



131
132
133
134
135
136
# File 'lib/xsys/api.rb', line 131

def self.update_cash_withdrawal_items(shop_code, cash_withdrawal_items)
  post_request('/cash_withdrawal_items', {
    shop_code: shop_code,
    cash_withdrawal_items: cash_withdrawal_items
  })[:body]
end

.update_cash_withdrawals(shop_code, cash_withdrawals) ⇒ Object



124
125
126
127
128
129
# File 'lib/xsys/api.rb', line 124

def self.update_cash_withdrawals(shop_code, cash_withdrawals)
  post_request('/cash_withdrawals', {
    shop_code: shop_code,
    cash_withdrawals: cash_withdrawals
  })[:body]
end

.update_product(product_id, attrs = {}) ⇒ Object



148
149
150
# File 'lib/xsys/api.rb', line 148

def self.update_product(product_id, attrs={})
  Model::Product.new(put_request("/products/#{product_id}", attrs)[:body])
end

.update_product_price_list(attrs = {}) ⇒ Object



152
153
154
# File 'lib/xsys/api.rb', line 152

def self.update_product_price_list(attrs={})
  put_request('/product_price_lists', attrs)[:body]
end