retentiongrid 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d0fa613d3babf6c177b1aac2f3ee7cd0fe7a1af
4
- data.tar.gz: 625ee2cab1d11aacd52ba112ee8a206e1ffef971
3
+ metadata.gz: 892f3b7d7a66383fdfae7da935da621d00155b21
4
+ data.tar.gz: 1b5e1bc5ceb13d5357d1263afa3ce56d5e94bafe
5
5
  SHA512:
6
- metadata.gz: 5aba78ecd284681abec3f5389656d0c4616f9e9d81475dc7212fd1a03998aa309640a789d7bfb969e3fe2ea66f295e77737f434364bd824c7fb172fd451b9e9f
7
- data.tar.gz: 27025e4f718fc732c5467b8aef7d64d9fa4b6a89864cd072ba05c6a7b9c5c49db93a82e24ab4431217e013aca56c4262534c4f3d7a959205dc2703d7ff51f539
6
+ metadata.gz: 57dd691a5f50ee232404b6397ed985167f4e9ad1a8e393ce8fcd06bd536a46697457bdf98b71ceb545e0379eba40b6c525eb9c938f7fe4d106578871eafaa8aa
7
+ data.tar.gz: 5a65f1b4f48bd3be18375840aaf26dfd6050c690b01841d33a1ece176444aa1fcc2e5fce347f816449a769625515f95aaa4403824669b4da9de7a5bc3aa67ca3
data/README.md CHANGED
@@ -26,10 +26,29 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
+ ### set you API key
30
+
29
31
  require 'retentiongrid'
30
32
  Retentiongrid::Api.api_key = "your_api_key"
33
+
34
+ ### Read from retentiongrid
35
+
31
36
  order = Retentiongrid::Order.find(1234)
32
37
 
38
+ ### Write to retentiongrid
39
+
40
+ order = Retentiongrid::Order.new({
41
+ status: 'ok',
42
+ order_id: 'R123',
43
+ customer_id: 'C321',
44
+ currency: 'EUR',
45
+ total_price: 35.99,
46
+ total_discounts: 0.0,
47
+ order_created_at: Time.now,
48
+ })
49
+ order.save
50
+
51
+
33
52
  ## Contributing
34
53
 
35
54
  1. Fork it ( https://github.com/[my-github-username]/retentiongrid/fork )
@@ -1,8 +1,56 @@
1
1
  module Retentiongrid
2
2
  class LineItem < Resource
3
3
 
4
- def initialize
5
- raise NotImplemented.new
4
+ BASE_PATH="/line_items".freeze
5
+
6
+ # The set of attributes defined by the API documentation
7
+ ATTRIBUTES_NAMES = [ :line_item_id, :order_id, :price, :quantity,
8
+ :product_id, :variant_id, :sku, :name
9
+ ].freeze
10
+
11
+ ATTRIBUTES_NAMES.each do |attrib|
12
+ attr_accessor attrib
13
+ end
14
+
15
+ def initialize(attribs={})
16
+ super
6
17
  end
18
+
19
+ # relations
20
+
21
+ def order=(order)
22
+ @order_id = order.order_id
23
+ @order = order
24
+ end
25
+
26
+ # API Stuff here
27
+
28
+ # Find a product with given id
29
+ # @param [Fixnum] product_id the prodct id to be found
30
+ # @return [LineItem] if found any
31
+ def self.find(line_item_id)
32
+ begin
33
+ result = Api.get("#{BASE_PATH}/#{line_item_id}")
34
+ new(result.parsed_response["rg_line_item"])
35
+ rescue NotFound
36
+ nil
37
+ end
38
+ end
39
+
40
+ # Create or update a line item with given id
41
+ # @return [LineItem] if successfully created or updated
42
+ # @raise [Httparty::Error] for all sorts of HTTP statuses.
43
+ def save!
44
+ result = Api.post("#{BASE_PATH}/#{line_item_id}", body: attributes.to_json)
45
+ new(result.parsed_response["rg_line_item"])
46
+ end
47
+
48
+ # Delete this line item at retention grid
49
+ # @return [Boolean] successfully deleted?
50
+ def destroy
51
+ Api.delete("#{BASE_PATH}/#{line_item_id}")
52
+ true
53
+ end
54
+
7
55
  end
8
56
  end
@@ -7,7 +7,7 @@ module Retentiongrid
7
7
  ATTRIBUTES_NAMES = [ :product_id, :available, :metadata,
8
8
  :title, :image_url, :currency, :price,
9
9
  :sale_price, :cost_price, :product_url,
10
- :product_created_at, :product_updated_at
10
+ :product_created_at, :product_updated_at, :meta
11
11
  ].freeze
12
12
 
13
13
  ATTRIBUTES_NAMES.each do |attrib|
@@ -1,3 +1,3 @@
1
1
  module Retentiongrid
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,14 @@
1
+ FactoryGirl.define do
2
+
3
+ sequence :line_item_id do |n|
4
+ n
5
+ end
6
+
7
+ factory :line_item do
8
+ line_item_id
9
+ order
10
+ quantity 1
11
+ price 10.99
12
+ sku 'SDSD'
13
+ end
14
+ end
@@ -15,5 +15,11 @@ FactoryGirl.define do
15
15
  image_url 'http://example.com/images/1.png'
16
16
  product_updated_at { Time.now - 86400 }
17
17
  product_created_at { Time.now - 161024 }
18
+ meta { Hash.new(
19
+ type: "red",
20
+ region: "napa valley",
21
+ country: "USA",
22
+ varietal: "pinot noir"
23
+ )}
18
24
  end
19
25
  end
@@ -7,7 +7,7 @@ RSpec.describe Customer do
7
7
  end
8
8
 
9
9
  it "sets the base path correctly" do
10
- expect(Customer::BASE_PATH).to eql '/customers'
10
+ expect(subject.class::BASE_PATH).to eql '/customers'
11
11
  end
12
12
 
13
13
  it "makes sure the customer id is populated" do
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ include Retentiongrid
3
+ RSpec.describe LineItem do
4
+
5
+ let :customer do
6
+ FactoryGirl.build(:customer)
7
+ end
8
+
9
+ let :order do
10
+ FactoryGirl.build(:order, customer: customer)
11
+ end
12
+
13
+ subject do
14
+ FactoryGirl.build(:line_item, order: order)
15
+ end
16
+
17
+ it "sets the base path correctly" do
18
+ expect(subject.class::BASE_PATH).to eql '/line_items'
19
+ end
20
+
21
+ it "makes sure the line item id is populated" do
22
+ expect(subject.line_item_id).to_not eql nil
23
+ end
24
+
25
+ context 'associations' do
26
+
27
+ it "sets up order association" do
28
+ expect(subject.order_id).to eql order.order_id
29
+ end
30
+ end
31
+
32
+ end
@@ -11,11 +11,19 @@ RSpec.describe Order do
11
11
  end
12
12
 
13
13
  it "sets the base path correctly" do
14
- expect(Order::BASE_PATH).to eql '/orders'
14
+ expect(subject.class::BASE_PATH).to eql '/orders'
15
15
  end
16
16
 
17
17
  it "makes sure the order id is populated" do
18
18
  expect(subject.order_id).not_to eql nil
19
19
  end
20
20
 
21
+ context 'associations' do
22
+
23
+ it "sets up customer association" do
24
+ expect(subject.customer_id).to eql customer.customer_id
25
+ end
26
+ end
27
+
28
+
21
29
  end
@@ -7,7 +7,7 @@ RSpec.describe Product do
7
7
  end
8
8
 
9
9
  it "sets the base path correctly" do
10
- expect(Product::BASE_PATH).to eql '/products'
10
+ expect(subject.class::BASE_PATH).to eql '/products'
11
11
  end
12
12
 
13
13
  it "makes sure the product id is populated" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retentiongrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Bünte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-17 00:00:00.000000000 Z
11
+ date: 2014-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -149,12 +149,14 @@ files:
149
149
  - log/.gitkeep
150
150
  - retentiongrid.gemspec
151
151
  - spec/factories/customers.rb
152
+ - spec/factories/line_items.rb
152
153
  - spec/factories/orders.rb
153
154
  - spec/factories/products.rb
154
155
  - spec/integration/customer_spec.rb
155
156
  - spec/integration/order_spec.rb
156
157
  - spec/integration/product_spec.rb
157
158
  - spec/models/customer_spec.rb
159
+ - spec/models/line_item_spec.rb
158
160
  - spec/models/order_spec.rb
159
161
  - spec/models/product_spec.rb
160
162
  - spec/spec_helper.rb
@@ -184,12 +186,14 @@ specification_version: 4
184
186
  summary: A ruby client for retentiongrid.com API.
185
187
  test_files:
186
188
  - spec/factories/customers.rb
189
+ - spec/factories/line_items.rb
187
190
  - spec/factories/orders.rb
188
191
  - spec/factories/products.rb
189
192
  - spec/integration/customer_spec.rb
190
193
  - spec/integration/order_spec.rb
191
194
  - spec/integration/product_spec.rb
192
195
  - spec/models/customer_spec.rb
196
+ - spec/models/line_item_spec.rb
193
197
  - spec/models/order_spec.rb
194
198
  - spec/models/product_spec.rb
195
199
  - spec/spec_helper.rb