retentiongrid 0.0.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 +7 -0
- data/.gitignore +56 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +24 -0
- data/lib/retentiongrid/api.rb +47 -0
- data/lib/retentiongrid/customer.rb +58 -0
- data/lib/retentiongrid/errors.rb +39 -0
- data/lib/retentiongrid/order.rb +71 -0
- data/lib/retentiongrid/version.rb +3 -0
- data/lib/retentiongrid.rb +9 -0
- data/log/.gitkeep +0 -0
- data/retentiongrid.gemspec +33 -0
- data/spec/factories/customers.rb +11 -0
- data/spec/factories/orders.rb +14 -0
- data/spec/integration/customer_spec.rb +52 -0
- data/spec/integration/order_spec.rb +83 -0
- data/spec/models/customer_spec.rb +19 -0
- data/spec/models/order_spec.rb +26 -0
- data/spec/spec_helper.rb +17 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1c260a3fac75b7eb9554b20a70288a5151d07e5
|
4
|
+
data.tar.gz: ed4661a6a5484c03722effc016a0c54c577bda7f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 813d5e58d046ec945e7992bbffbe9a3935143f39af01c46eec8a8e9f0f7fb1e60c03fdb18b21f164086593f9dc1d7c653039cca992373e17779e66f01308ccb4
|
7
|
+
data.tar.gz: 25d7b57cb53bdaac461cd13d80d65480af98299de786f87c411537edc5f4bf7217032f0da27d6301b9a5e0b3f341555f9f9e7df743c9a9024892371d1d21c683
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
/vendor
|
12
|
+
/log/*.log
|
13
|
+
|
14
|
+
## Specific to RubyMotion:
|
15
|
+
.dat*
|
16
|
+
.repl_history
|
17
|
+
build/
|
18
|
+
|
19
|
+
## Documentation cache and generated files:
|
20
|
+
/.yardoc/
|
21
|
+
/_yardoc/
|
22
|
+
/doc/
|
23
|
+
/rdoc/
|
24
|
+
|
25
|
+
## Environment normalisation:
|
26
|
+
/.bundle/
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
.bundle
|
38
|
+
.config
|
39
|
+
.yardoc
|
40
|
+
Gemfile.lock
|
41
|
+
InstalledFiles
|
42
|
+
_yardoc
|
43
|
+
coverage
|
44
|
+
doc/
|
45
|
+
lib/bundler/man
|
46
|
+
pkg
|
47
|
+
rdoc
|
48
|
+
spec/reports
|
49
|
+
test/tmp
|
50
|
+
test/version_tmp
|
51
|
+
tmp
|
52
|
+
*.bundle
|
53
|
+
*.so
|
54
|
+
*.o
|
55
|
+
*.a
|
56
|
+
mkmf.log
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Christoph Bünte
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Christoph Bünte
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Retention::Grid
|
2
|
+
|
3
|
+
A ruby client for retentiongrid.com API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'retentiongrid'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install retentiongrid
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'retentiongrid'
|
22
|
+
Retentiongrid::Api.api_key = "your_api_key"
|
23
|
+
order = Retentiongrid::Order.find(1234)
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/retentiongrid/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'yard'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
YARD::Rake::YardocTask.new do |t|
|
11
|
+
t.files = ['lib/**/*.rb'] # optional
|
12
|
+
# t.options = ['--any', '--extra', '--opts'] # optional
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Open an irb session preloaded with this library"
|
16
|
+
task :console do
|
17
|
+
sh "irb -rubygems -I lib -r retentiongrid.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :c => :console
|
21
|
+
|
22
|
+
task :default => :spec
|
23
|
+
|
24
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'logger'
|
3
|
+
module Retentiongrid
|
4
|
+
|
5
|
+
# The Api class handles all calls to the Retentiongrid API.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
# require 'retentiongrid'
|
9
|
+
# Retentiongrid::Api.api_key = "your_api_key"
|
10
|
+
# order = Retentiongrid::Order.find(1234)
|
11
|
+
class Api
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
base_uri 'https://app.retentiongrid.com/api'
|
15
|
+
logger ::Logger.new("log/httparty.log"), :debug, :curl
|
16
|
+
|
17
|
+
def self.api_key=(api_key)
|
18
|
+
default_params token: api_key
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get(path, options={}, &block)
|
22
|
+
response = super(path, options={}, &block)
|
23
|
+
check_response_codes(response)
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.check_response_codes(response)
|
30
|
+
body = response.body
|
31
|
+
case response.code.to_i
|
32
|
+
when 200 then return
|
33
|
+
when 400 then raise BadRequest.new(body)
|
34
|
+
when 401 then raise Unauthorized.new(body)
|
35
|
+
when 403 then raise Forbidden.new(body)
|
36
|
+
when 404 then raise NotFound.new(body)
|
37
|
+
when 405 then raise MethodNotAllowed.new(body)
|
38
|
+
when 410 then raise Gone.new(body)
|
39
|
+
when 500 then raise ServerError, 'Internal Server Error'
|
40
|
+
when 503 then raise Unavailable, 'Service Unavailable'
|
41
|
+
else raise "Unknown response code: #{response.code}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Retentiongrid
|
2
|
+
class Customer
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
ATTRIBUTES_NAMES = [ :customer_id, :full_name, :first_name, :email,
|
6
|
+
:country, :state, :city, :postal_code, :tags,
|
7
|
+
:accepts_email_marketing ].freeze
|
8
|
+
|
9
|
+
ATTRIBUTES_NAMES.each do |attrib|
|
10
|
+
attr_accessor attrib
|
11
|
+
end
|
12
|
+
|
13
|
+
validates :customer_id, :full_name, presence: true
|
14
|
+
|
15
|
+
def initialize(attribs={})
|
16
|
+
attribs.each do |attrib, value|
|
17
|
+
self.send("#{attrib}=", value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# API Stuff here
|
22
|
+
|
23
|
+
# Find a customer with given id
|
24
|
+
# @param [Fixnum] customer_id the customer id to be found
|
25
|
+
# @return [Customer] if found any
|
26
|
+
def self.find(customer_id)
|
27
|
+
begin
|
28
|
+
result = Api.get("/customers/#{customer_id}")
|
29
|
+
new(result.parsed_response)
|
30
|
+
rescue NotFound
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def save
|
38
|
+
result = Api.post("/customers/#{customer_id}", attributes)
|
39
|
+
Customer.new(result.parsed_response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def save!
|
43
|
+
!!save
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroy
|
47
|
+
res = Api.delete("/customers/#{customer_id}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def attributes
|
51
|
+
ATTRIBUTES_NAMES.inject({}) do |attribs, attrib_name|
|
52
|
+
attribs[attrib_name] = self.send(attrib_name)
|
53
|
+
attribs
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Retentiongrid
|
2
|
+
|
3
|
+
# This error occurs when the request send to the server could not be parsed.
|
4
|
+
class ParseError < HTTParty::Error; end
|
5
|
+
|
6
|
+
# An object was not found in the database.
|
7
|
+
class NotFound < HTTParty::Error; end
|
8
|
+
|
9
|
+
# The API returned HTTP 400 (Bad Request).
|
10
|
+
class BadRequest < HTTParty::Error; end # 400
|
11
|
+
|
12
|
+
# The API operation wasn't authorized. This happens if you didn't set the user and
|
13
|
+
# password for a write operation.
|
14
|
+
class Unauthorized < HTTParty::Error; end # 401
|
15
|
+
|
16
|
+
# You don't have sufficient permissions to make that request.
|
17
|
+
class Forbidden < HTTParty::Error; end # 403
|
18
|
+
|
19
|
+
# The object was not found (HTTP 404). Generally means that the object doesn't exist
|
20
|
+
# and never has.
|
21
|
+
class NotFound < HTTParty::Error; end # 404
|
22
|
+
|
23
|
+
# If the request is not a HTTP PUT request
|
24
|
+
class MethodNotAllowed < HTTParty::Error; end # 405
|
25
|
+
|
26
|
+
# The object was not found (HTTP 410), but it used to exist. This generally means
|
27
|
+
# that the object existed at some point, but was deleted.
|
28
|
+
class Gone < HTTParty::Error; end # 410
|
29
|
+
|
30
|
+
# Unspecified API server error.
|
31
|
+
class ServerError < HTTParty::Error; end # 500
|
32
|
+
|
33
|
+
# When the API service times out or returns an HTTP 503 status.
|
34
|
+
class Unavailable < HTTParty::Error; end # 503
|
35
|
+
|
36
|
+
# This method is not implemented yet.
|
37
|
+
class NotImplemented < HTTParty::Error; end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Retentiongrid
|
2
|
+
# Retentiongrid Order
|
3
|
+
#
|
4
|
+
# To create a new Retentiongrid::Order object:
|
5
|
+
# order = Retention::Order.new(:id => "123", :lat => "52.2", :lon => "13.4", :changeset => "12", :user => "fred", :uid => "123", :visible => true, :timestamp => "2005-07-30T14:27:12+01:00")
|
6
|
+
#
|
7
|
+
# To get a order from the API:
|
8
|
+
# order = Retention::Order.find(17)
|
9
|
+
#
|
10
|
+
class Order
|
11
|
+
include ActiveModel::Validations
|
12
|
+
|
13
|
+
ATTRIBUTES_NAMES = [ :order_id, :customer_id, :status, :total_price, :total_discounts,
|
14
|
+
:currency, :canceled_shipped, :canceled_shop_fault, :order_created_at
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
ATTRIBUTES_NAMES.each do |attrib|
|
18
|
+
attr_accessor attrib
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :customer
|
22
|
+
|
23
|
+
validates :order_id, :customer_id, :currency, :total_price, :order_created_at, presence: true
|
24
|
+
|
25
|
+
def initialize(attribs={})
|
26
|
+
attribs.each do |attrib, value|
|
27
|
+
self.send("#{attrib}=", value)
|
28
|
+
end
|
29
|
+
@order_created_at = Time.parse(order_created_at) unless order_created_at.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# relations
|
34
|
+
|
35
|
+
def customer=(customer)
|
36
|
+
@customer_id = customer.customer_id
|
37
|
+
@customer = customer
|
38
|
+
end
|
39
|
+
|
40
|
+
# API Stuff here
|
41
|
+
|
42
|
+
# Find an order with given id
|
43
|
+
# @param [Fixnum] order_id the order id to be found
|
44
|
+
# @return [Order] if found any
|
45
|
+
def self.find(order_id)
|
46
|
+
begin
|
47
|
+
result = Api.get("/orders/#{order_id}")
|
48
|
+
new(result.parsed_response)
|
49
|
+
rescue NotFound
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def save
|
55
|
+
result = Api.post("/orders/#{order_id}", attributes)
|
56
|
+
Order.new(result.parsed_response)
|
57
|
+
end
|
58
|
+
|
59
|
+
def destroy
|
60
|
+
res = Api.delete("/orders/#{order_id}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def attributes
|
64
|
+
ATTRIBUTES_NAMES.inject({}) do |attribs, attrib_name|
|
65
|
+
attribs[attrib_name] = self.send(attrib_name)
|
66
|
+
attribs
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/log/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'retentiongrid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "retentiongrid"
|
8
|
+
spec.version = Retentiongrid::VERSION
|
9
|
+
spec.authors = ["Christoph Bünte"]
|
10
|
+
spec.email = ["info@christophbuente.de"]
|
11
|
+
spec.summary = "A ruby client for retentiongrid.com API."
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'httparty', '0.13.1'
|
21
|
+
spec.add_dependency 'activemodel', '>=3.2.0'
|
22
|
+
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'yard'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
spec.add_development_dependency 'shoulda-matchers'
|
30
|
+
spec.add_development_dependency 'webmock'
|
31
|
+
spec.add_development_dependency 'factory_girl'
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Retentiongrid
|
3
|
+
RSpec.describe Customer do
|
4
|
+
|
5
|
+
before do
|
6
|
+
WebMock.disable_net_connect!
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid_customer
|
10
|
+
<<-EOF
|
11
|
+
{
|
12
|
+
"customer_id": "C123",
|
13
|
+
"first_name": "John",
|
14
|
+
"full_name": "John Smith",
|
15
|
+
"email": "john.smith@example.com",
|
16
|
+
"country": "DE",
|
17
|
+
"city": "Berlin",
|
18
|
+
"state": "Berlin",
|
19
|
+
"postal_code": "10437",
|
20
|
+
"tags": "wholesale",
|
21
|
+
"accepts_email_marketing": "true"
|
22
|
+
}
|
23
|
+
EOF
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:api) { Api.new }
|
27
|
+
|
28
|
+
context '#find' do
|
29
|
+
|
30
|
+
subject do
|
31
|
+
stub_request(:get, "http://retentiongrid.apiary-mock.com/customers/C123").
|
32
|
+
to_return(:status => 200, :body => valid_customer, :headers => {'Content-Type' => 'application/json'})
|
33
|
+
Customer.find('C123')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should build a Customer from API response" do
|
37
|
+
expect(subject.class).to eql Retentiongrid::Customer
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should parse customer_id correctly" do
|
41
|
+
expect(subject.customer_id).to eql 'C123'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context '#create' do
|
47
|
+
end
|
48
|
+
|
49
|
+
context '#delete' do
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Retentiongrid
|
3
|
+
RSpec.describe Order do
|
4
|
+
|
5
|
+
before do
|
6
|
+
WebMock.disable_net_connect!
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid_order
|
10
|
+
<<-EOF
|
11
|
+
{
|
12
|
+
"order_id": "A123",
|
13
|
+
"customer_id": "C123",
|
14
|
+
"status": "ok",
|
15
|
+
"total_price": 12.00,
|
16
|
+
"total_discounts": 1.00,
|
17
|
+
"currency": "EUR",
|
18
|
+
"canceled_shipped": false,
|
19
|
+
"canceled_shop_fault": false,
|
20
|
+
"order_created_at": "2014-03-12 13:35:10"
|
21
|
+
}
|
22
|
+
EOF
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:api) { Api.new }
|
26
|
+
|
27
|
+
context '#find' do
|
28
|
+
|
29
|
+
subject do
|
30
|
+
stub_request(:get, "http://retentiongrid.apiary-mock.com/orders/A123").
|
31
|
+
to_return(:status => 200, :body => valid_order, :headers => {'Content-Type' => 'application/json'})
|
32
|
+
Order.find('A123')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should build an Order from API response" do
|
36
|
+
expect(subject.class).to eql Retentiongrid::Order
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should parse order_id correctly" do
|
40
|
+
expect(subject.order_id).to eql 'A123'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should parse customer_id correctly" do
|
44
|
+
expect(subject.customer_id).to eql 'C123'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should parse status correctly" do
|
48
|
+
expect(subject.status).to eql 'ok'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should parse total_price correctly" do
|
52
|
+
expect(subject.total_price).to eql 12.0
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should parse total_discounts correctly" do
|
56
|
+
expect(subject.total_discounts).to eql 1.0
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should parse currency correctly" do
|
60
|
+
expect(subject.currency).to eql "EUR"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should parse canceled_shipped correctly" do
|
64
|
+
expect(subject.canceled_shipped).to eql false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should parse canceled_shop_fault correctly" do
|
68
|
+
expect(subject.canceled_shop_fault).to eql false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should parse order_created_at correctly" do
|
72
|
+
expect(subject.order_created_at).to eql Time.parse("2014-03-12 13:35:10")
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context '#create' do
|
78
|
+
end
|
79
|
+
|
80
|
+
context '#delete' do
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Retentiongrid
|
3
|
+
RSpec.describe Customer do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
FactoryGirl.build(:customer)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "validations" do
|
10
|
+
it { expect(subject).to validate_presence_of :customer_id }
|
11
|
+
it { expect(subject).to validate_presence_of :full_name }
|
12
|
+
it { expect(subject).to be_valid }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "makes sure the order id is populated" do
|
16
|
+
expect(subject.customer_id).to eql 1
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Retentiongrid
|
3
|
+
RSpec.describe Order do
|
4
|
+
|
5
|
+
let :customer do
|
6
|
+
FactoryGirl.build(:customer)
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
FactoryGirl.build(:order, customer: customer)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "validations" do
|
14
|
+
it { expect(subject).to validate_presence_of :order_id }
|
15
|
+
it { expect(subject).to validate_presence_of :customer_id }
|
16
|
+
it { expect(subject).to validate_presence_of :currency }
|
17
|
+
it { expect(subject).to validate_presence_of :total_price }
|
18
|
+
it { expect(subject).to validate_presence_of :order_created_at }
|
19
|
+
it { expect(subject).to be_valid }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "makes sure the order id is populated" do
|
23
|
+
expect(subject.order_id).to eql 1
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
require 'factory_girl'
|
3
|
+
require 'retentiongrid'
|
4
|
+
require 'shoulda/matchers'
|
5
|
+
|
6
|
+
require 'rspec'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
|
10
|
+
config.mock_with :rspec
|
11
|
+
config.include FactoryGirl::Syntax::Methods
|
12
|
+
end
|
13
|
+
|
14
|
+
FactoryGirl.find_definitions
|
15
|
+
|
16
|
+
# HTTP requests are disabled, but make sure the mocking url is being used in test mode
|
17
|
+
Retentiongrid::Api::base_uri 'http://retentiongrid.apiary-mock.com'
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: retentiongrid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christoph Bünte
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: shoulda-matchers
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: factory_girl
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- info@christophbuente.de
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- lib/retentiongrid.rb
|
154
|
+
- lib/retentiongrid/api.rb
|
155
|
+
- lib/retentiongrid/customer.rb
|
156
|
+
- lib/retentiongrid/errors.rb
|
157
|
+
- lib/retentiongrid/order.rb
|
158
|
+
- lib/retentiongrid/version.rb
|
159
|
+
- log/.gitkeep
|
160
|
+
- retentiongrid.gemspec
|
161
|
+
- spec/factories/customers.rb
|
162
|
+
- spec/factories/orders.rb
|
163
|
+
- spec/integration/customer_spec.rb
|
164
|
+
- spec/integration/order_spec.rb
|
165
|
+
- spec/models/customer_spec.rb
|
166
|
+
- spec/models/order_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
homepage: ''
|
169
|
+
licenses:
|
170
|
+
- MIT
|
171
|
+
metadata: {}
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.2.0
|
189
|
+
signing_key:
|
190
|
+
specification_version: 4
|
191
|
+
summary: A ruby client for retentiongrid.com API.
|
192
|
+
test_files:
|
193
|
+
- spec/factories/customers.rb
|
194
|
+
- spec/factories/orders.rb
|
195
|
+
- spec/integration/customer_spec.rb
|
196
|
+
- spec/integration/order_spec.rb
|
197
|
+
- spec/models/customer_spec.rb
|
198
|
+
- spec/models/order_spec.rb
|
199
|
+
- spec/spec_helper.rb
|
200
|
+
has_rdoc:
|