giftrocket_ruby 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/giftrocket/base.rb +18 -0
- data/lib/giftrocket/error.rb +15 -0
- data/lib/giftrocket/funding_source.rb +28 -0
- data/lib/giftrocket/gift.rb +43 -0
- data/lib/giftrocket/order.rb +57 -0
- data/lib/giftrocket/payment.rb +14 -0
- data/lib/giftrocket/style.rb +31 -0
- data/lib/giftrocket/user.rb +13 -0
- data/lib/giftrocket/version.rb +3 -0
- data/lib/giftrocket.rb +11 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d2750a679373c1986a28faabe07e6a85e1671d7
|
4
|
+
data.tar.gz: dd890d388350e0f3ffcad7eed8a7819c150f1a69
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a725368f77ce3fcccada946de3bc7ab1270d113472d737e3afa89caa8cb9497c5f48287ccd62fd12f0569fb2855bf00cb34b1110ec801b5040861b09649a026
|
7
|
+
data.tar.gz: da81134d5c17d9e3b334e243a72582b17ffd967156fbee5c3fda5dddc0c989189de35774907714d8f03960fb44f46ffc2d172ca6e22997fc7a8efc4106fe3e22
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Giftrocket
|
2
|
+
@@config = {
|
3
|
+
base_api_uri: 'https://www.giftrocket.com/api/v1/'
|
4
|
+
}
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
@@config
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield @@config
|
12
|
+
end
|
13
|
+
|
14
|
+
# Access token
|
15
|
+
def self.default_options
|
16
|
+
{access_token: @@config[:access_token]}
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Giftrocket
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
11
|
+
errors = response_json[:errors]
|
12
|
+
"Code: #{@response.code}; Data: #{errors}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Giftrocket
|
2
|
+
class FundingSource
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
base_uri "#{Giftrocket.config[:base_api_uri]}funding_sources/"
|
6
|
+
|
7
|
+
attr_accessor :id, :method, :meta
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
attributes = attributes.with_indifferent_access
|
11
|
+
self.id = attributes[:id]
|
12
|
+
self.method = attributes[:method]
|
13
|
+
self.meta = attributes[:meta]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list
|
17
|
+
response = get '/', query: Giftrocket.default_options, format: 'json'
|
18
|
+
if response.success?
|
19
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
20
|
+
response_json[:funding_sources].map do |funding_souce_attributes|
|
21
|
+
Giftrocket::FundingSource.new(funding_souce_attributes)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise Giftrocket::Error.new(response)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Giftrocket
|
2
|
+
class Gift
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
base_uri "#{Giftrocket.config[:base_api_uri]}gifts/"
|
6
|
+
|
7
|
+
attr_accessor :id, :order_id, :amount, :message, :style_id, :status, :recipient, :events
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
attributes = attributes.with_indifferent_access
|
11
|
+
self.id = attributes[:id]
|
12
|
+
self.order_id = attributes[:order_id]
|
13
|
+
self.amount = attributes[:amount]
|
14
|
+
self.message = attributes[:message]
|
15
|
+
self.style_id = attributes[:style_id]
|
16
|
+
self.status = attributes[:status]
|
17
|
+
self.recipient = Giftrocket::User.new(attributes[:recipient])
|
18
|
+
self.events = attributes[:events]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.list
|
22
|
+
response = get '/', query: Giftrocket.default_options, format: 'json'
|
23
|
+
if response.success?
|
24
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
25
|
+
response_json[:gifts].map do |gift_attributes|
|
26
|
+
Giftrocket::Gift.new(gift_attributes)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
raise Giftrocket::Error.new(response)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.retrieve(id)
|
34
|
+
response = get "/#{id}", query: Giftrocket.default_options, format: 'json'
|
35
|
+
if response.success?
|
36
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
37
|
+
Giftrocket::Gift.new(response_json[:gift])
|
38
|
+
else
|
39
|
+
raise Giftrocket::Error.new(response)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Giftrocket
|
2
|
+
class Order
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
base_uri "#{Giftrocket.config[:base_api_uri]}orders/"
|
6
|
+
|
7
|
+
attr_accessor :id, :gifts, :payment, :sender
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
attributes = attributes.with_indifferent_access
|
11
|
+
self.id = attributes[:id]
|
12
|
+
self.gifts = attributes[:gifts].map do |gift_attributes|
|
13
|
+
Gift.new(gift_attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
self.payment = Giftrocket::Payment.new(attributes[:payment])
|
17
|
+
self.sender = Giftrocket::User.new(attributes[:sender])
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create!(funding_source_id, gifts_data_array)
|
21
|
+
data_to_post = {
|
22
|
+
funding_source_id: funding_source_id,
|
23
|
+
gifts: gifts_data_array
|
24
|
+
}.merge(Giftrocket.default_options)
|
25
|
+
|
26
|
+
response = post '/', body: data_to_post.to_json, headers: { 'Content-Type' => 'application/json' }
|
27
|
+
if response.success?
|
28
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
29
|
+
Giftrocket::Order.new(response_json[:order])
|
30
|
+
else
|
31
|
+
raise Giftrocket::Error.new(response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.list
|
36
|
+
response = get '/', query: Giftrocket.default_options, format: 'json'
|
37
|
+
if response.success?
|
38
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
39
|
+
response_json[:orders].map do |order_attributes|
|
40
|
+
Giftrocket::Order.new(order_attributes)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
raise Giftrocket::Error.new(response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.retrieve(id)
|
48
|
+
response = get "/#{id}", query: Giftrocket.default_options, format: 'json'
|
49
|
+
if response.success?
|
50
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
51
|
+
Giftrocket::Order.new(response_json[:order])
|
52
|
+
else
|
53
|
+
raise Giftrocket::Error.new(response)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Giftrocket
|
2
|
+
class Payment
|
3
|
+
|
4
|
+
attr_accessor :amount, :fees, :total, :funding_source_id
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
self.amount = attributes[:amount]
|
8
|
+
self.fees = attributes[:fees]
|
9
|
+
self.total = attributes[:total]
|
10
|
+
self.funding_source_id = attributes[:funding_source_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Giftrocket
|
2
|
+
class Style
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
base_uri "#{Giftrocket.config[:base_api_uri]}styles/"
|
6
|
+
|
7
|
+
attr_accessor :id, :card
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
attributes = attributes.with_indifferent_access
|
11
|
+
self.id = attributes[:id]
|
12
|
+
self.card = attributes[:card]
|
13
|
+
end
|
14
|
+
|
15
|
+
def url
|
16
|
+
card && card[:url]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.list
|
20
|
+
response = get '/', query: Giftrocket.default_options, format: 'json'
|
21
|
+
if response.success?
|
22
|
+
response_json = JSON.parse(response.body).with_indifferent_access
|
23
|
+
response_json[:styles].map do |style_attributes|
|
24
|
+
Giftrocket::Style.new(style_attributes)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
raise Giftrocket::Error.new(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/giftrocket.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
+
require 'giftrocket/base'
|
4
|
+
require 'giftrocket/funding_source'
|
5
|
+
require 'giftrocket/gift'
|
6
|
+
require 'giftrocket/style'
|
7
|
+
require 'giftrocket/order'
|
8
|
+
require 'giftrocket/payment'
|
9
|
+
require 'giftrocket/user'
|
10
|
+
require 'giftrocket/error'
|
11
|
+
require 'giftrocket/version'
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: giftrocket_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GiftRocket
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.14.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.14.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.20'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.20'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- support@giftrocket.com
|
114
|
+
- kapil@giftrocket.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- lib/giftrocket.rb
|
120
|
+
- lib/giftrocket/base.rb
|
121
|
+
- lib/giftrocket/error.rb
|
122
|
+
- lib/giftrocket/funding_source.rb
|
123
|
+
- lib/giftrocket/gift.rb
|
124
|
+
- lib/giftrocket/order.rb
|
125
|
+
- lib/giftrocket/payment.rb
|
126
|
+
- lib/giftrocket/style.rb
|
127
|
+
- lib/giftrocket/user.rb
|
128
|
+
- lib/giftrocket/version.rb
|
129
|
+
homepage: https://github.com/GiftRocket/giftrocket-ruby
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.6
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: GiftRocket Ruby API SDK
|
153
|
+
test_files: []
|