retentiongrid 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/retentiongrid/line_item.rb +50 -2
- data/lib/retentiongrid/product.rb +1 -1
- data/lib/retentiongrid/version.rb +1 -1
- data/spec/factories/line_items.rb +14 -0
- data/spec/factories/products.rb +6 -0
- data/spec/models/customer_spec.rb +1 -1
- data/spec/models/line_item_spec.rb +32 -0
- data/spec/models/order_spec.rb +9 -1
- data/spec/models/product_spec.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 892f3b7d7a66383fdfae7da935da621d00155b21
|
4
|
+
data.tar.gz: 1b5e1bc5ceb13d5357d1263afa3ce56d5e94bafe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
5
|
-
|
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|
|
data/spec/factories/products.rb
CHANGED
@@ -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
|
@@ -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
|
data/spec/models/order_spec.rb
CHANGED
@@ -11,11 +11,19 @@ RSpec.describe Order do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "sets the base path correctly" do
|
14
|
-
expect(
|
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
|
data/spec/models/product_spec.rb
CHANGED
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.
|
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-
|
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
|