lightspeed_ruby 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23d00fafbbf12f894ddf301401d959ddef7b6593
4
- data.tar.gz: bdb344a64f91734d326dffeb1313d8ebc56d19d9
3
+ metadata.gz: 99c19349a0b1ae4455685c1725d8d8dffedc43a7
4
+ data.tar.gz: 33663fccc4c8bb1a93d1497d176764f29545cbbb
5
5
  SHA512:
6
- metadata.gz: 10f55b602ebc06933c9f41629058bcc894611d817a9f2cc6d99024940ad7be2369c459793cee3b31e1da55c035c8deba503b6e6ef5b9312fe4c9cefec77eeef9
7
- data.tar.gz: 56e09be4e89944d380d1bbc528afa7bed17bfde412ba3fe4f56010c96ff6abcef4e5fbc2ccfcb8df8fc50a3bdec5eab1367a56f9021d5f0c28402a0d0e1c7513
6
+ metadata.gz: 7480af20b6955a1d385b4559878602e063a0ffdbf76d021d93cc6663fcd157e32aab921118376a6d9c95fec0fda72c73de0a3f84c64e6098277e52a9d0e8b042
7
+ data.tar.gz: 69a5263c9fbb6a84e91a7c0a91eefd5b7e57d44cc69bd0a2375860a42d8867b049704bfba45cf0469211d0070971f17d51d083fc4824429801563877803c2abc
@@ -0,0 +1,27 @@
1
+ module Lightspeed
2
+ module API
3
+ class Categories
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def all
9
+ client.get("Account/#{client.account_id}/Category.json").body
10
+ end
11
+
12
+ def find(item_id, with: [])
13
+ client.get("Account/#{client.account_id}/Category/#{item_id}.json", relations: with).body
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :client
19
+
20
+ def chosen_relations(with)
21
+ with.map do |relation|
22
+ relation.to_s.camelize
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ module Lightspeed
2
+ module API
3
+ class Customers
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def find(customer_id, with: [])
9
+ client.get("Account/#{client.account_id}/Customer/#{customer_id}.json", relations: with).body
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :client
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Lightspeed
2
+ module API
3
+ class Items
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def find(item_id, with: [])
9
+ client.get("Account/#{client.account_id}/Item/#{item_id}.json", relations: with).body
10
+ end
11
+
12
+ def create(attributes = {})
13
+ client.post("Account/#{client.account_id}/Item.json", body: attributes).body
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :client
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require "lightspeed/api/sales/sale_lines"
2
+
3
+ module Lightspeed
4
+ module API
5
+ class Sales
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def sale_lines; API::Sales::SaleLines.new(client); end
11
+
12
+ private
13
+
14
+ attr_reader :client
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Lightspeed
2
+ module API
3
+ class Sales
4
+ class SaleLines
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def all(sale_id)
10
+ client.
11
+ get("Account/#{client.account_id}/Sale/#{sale_id}/SaleLine.json").
12
+ body
13
+ end
14
+
15
+ def create(attributes = {})
16
+ client.post("Account/#{client.account_id}/Sale/#{attributes[:saleID]}/SaleLine.json", body: attributes).body
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :client
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,9 @@
1
1
  require "lightspeed/api/tokens"
2
2
  require "lightspeed/api/accounts"
3
+ require "lightspeed/api/sales"
4
+ require "lightspeed/api/customers"
5
+ require "lightspeed/api/items"
6
+ require "lightspeed/api/categories"
3
7
 
4
8
  module Lightspeed
5
9
  class Client
@@ -16,11 +20,19 @@ module Lightspeed
16
20
  @account_id = account_id
17
21
  end
18
22
 
19
- def get(url, params: {})
20
- conn.get(url, params)
23
+ def get(url, params: {}, relations: [])
24
+ conn.get(url, params.merge(load_relations: "[#{relation_names(relations)}]"))
25
+ end
26
+
27
+ def post(url, body: {})
28
+ conn.post(url, body)
21
29
  end
22
30
 
23
31
  def accounts; API::Accounts.new(self); end
32
+ def sales; API::Sales.new(self); end
33
+ def customers; API::Customers.new(self); end
34
+ def items; API::Items.new(self); end
35
+ def categories; API::Categories.new(self); end
24
36
 
25
37
  private
26
38
 
@@ -32,5 +44,11 @@ module Lightspeed
32
44
  f.adapter Faraday.default_adapter
33
45
  end
34
46
  end
47
+
48
+ def relation_names(relations)
49
+ relations.map do |relation|
50
+ "\"#{relation.to_s.camelize}\""
51
+ end.join(",")
52
+ end
35
53
  end
36
54
  end
@@ -1,3 +1,3 @@
1
1
  module Lightspeed
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightspeed_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zamith
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-19 00:00:00.000000000 Z
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,11 @@ files:
98
98
  - bin/setup
99
99
  - lib/lightspeed.rb
100
100
  - lib/lightspeed/api/accounts.rb
101
+ - lib/lightspeed/api/categories.rb
102
+ - lib/lightspeed/api/customers.rb
103
+ - lib/lightspeed/api/items.rb
104
+ - lib/lightspeed/api/sales.rb
105
+ - lib/lightspeed/api/sales/sale_lines.rb
101
106
  - lib/lightspeed/api/tokens.rb
102
107
  - lib/lightspeed/client.rb
103
108
  - lib/lightspeed/errors/missing_refresh_token.rb