giftrocket_ruby 0.1.6 → 1.0.0

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: faacf10d52471a8941368d5978ed7045953371fd
4
- data.tar.gz: a9dce7b5e22ed1f4b8620c82a6f44e753f5e1a1c
3
+ metadata.gz: b6c4a8d698edb670e8d9b7325fab957670b6ddaf
4
+ data.tar.gz: db009b868daa13cbcd257e04c9f3aadd3554dc6e
5
5
  SHA512:
6
- metadata.gz: fac7f55d2a544b569a8a83168be396531e08041a15759d335bd4c66ad3e67e8c6dde0779b6ce035d382b8404563fa69fc78f089d5177f16c17e03dd4b437428b
7
- data.tar.gz: 6d12332ede08b4bb6fd4453d0b6ac295b783c06cdfde0e4af65fc7e80004d8eb71339e03efe291912649730a817abf4e6464e367f7a0886ba76fca9c4fc558a9
6
+ metadata.gz: ccfd58e34a42becb546421e5fa97072e800fb75b7dd644a151c4da4d26b8fbd17404733300f694d7749aa0e22d83f58f25d5a7e670a7453e0e4a5f7f1e317b11
7
+ data.tar.gz: 003a59c7f1d97fa64c0442d01ee16787fe553d857e91eb5333675038c8653f1c6b0a217f5e8d76c42c95ea41508db7d75e915b1c410301155c468801e05c4841
data/lib/giftrocket.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'httparty'
2
2
  require 'active_support/core_ext/hash/indifferent_access'
3
3
  require 'giftrocket/base'
4
+ require 'giftrocket/request'
4
5
  require 'giftrocket/funding_source'
5
6
  require 'giftrocket/gift'
6
7
  require 'giftrocket/style'
7
8
  require 'giftrocket/order'
9
+ require 'giftrocket/organization'
10
+ require 'giftrocket/organization_member'
8
11
  require 'giftrocket/payment'
9
12
  require 'giftrocket/user'
10
13
  require 'giftrocket/error'
@@ -1,9 +1,6 @@
1
1
  module Giftrocket
2
2
  class FundingSource
3
3
 
4
- include HTTParty
5
- base_uri "#{Giftrocket.config[:base_api_uri]}funding_sources/"
6
-
7
4
  attr_accessor :id, :method, :meta
8
5
 
9
6
  def initialize(attributes)
@@ -13,15 +10,13 @@ module Giftrocket
13
10
  self.meta = attributes[:meta]
14
11
  end
15
12
 
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)
13
+ def self.list(filters={})
14
+ Giftrocket::Request.get(
15
+ 'funding_sources',
16
+ query: filters.merge(Giftrocket.default_options),
17
+ format: 'json'
18
+ )[:funding_sources].map do |funding_souce_attributes|
19
+ Giftrocket::FundingSource.new(funding_souce_attributes)
25
20
  end
26
21
  end
27
22
  end
@@ -1,10 +1,7 @@
1
1
  module Giftrocket
2
2
  class Gift
3
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
4
+ attr_accessor :id, :order_id, :amount, :message, :style_id, :status, :recipient, :sender, :events
8
5
 
9
6
  def initialize(attributes)
10
7
  attributes = attributes.with_indifferent_access
@@ -14,31 +11,26 @@ module Giftrocket
14
11
  self.message = attributes[:message]
15
12
  self.style_id = attributes[:style_id]
16
13
  self.status = attributes[:status]
14
+ self.sender = attributes[:sender]
17
15
  self.recipient = Giftrocket::User.new(attributes[:recipient])
18
16
  self.events = attributes[:events]
19
17
  end
20
18
 
21
- def self.list(query={})
22
- query = query.merge(Giftrocket.default_options)
23
- response = get '/', query: query, format: 'json'
24
- if response.success?
25
- response_json = JSON.parse(response.body).with_indifferent_access
26
- response_json[:gifts].map do |gift_attributes|
27
- Giftrocket::Gift.new(gift_attributes)
28
- end
29
- else
30
- raise Giftrocket::Error.new(response)
19
+ def self.list(filters={})
20
+ response = Giftrocket::Request.get(
21
+ 'gifts',
22
+ query: filters.merge(Giftrocket.default_options),
23
+ format: 'json'
24
+ )[:gifts].map do |gift_attributes|
25
+ Giftrocket::Gift.new(gift_attributes)
31
26
  end
32
27
  end
33
28
 
34
29
  def self.retrieve(id)
35
- response = get "/#{id}", query: Giftrocket.default_options, format: 'json'
36
- if response.success?
37
- response_json = JSON.parse(response.body).with_indifferent_access
38
- Giftrocket::Gift.new(response_json[:gift])
39
- else
40
- raise Giftrocket::Error.new(response)
41
- end
30
+ response = Giftrocket::Request.get "gifts/#{id}",
31
+ query: Giftrocket.default_options,
32
+ format: 'json'
33
+ Giftrocket::Gift.new(response[:gift])
42
34
  end
43
35
  end
44
36
  end
@@ -1,14 +1,12 @@
1
1
  module Giftrocket
2
2
  class Order
3
3
 
4
- include HTTParty
5
- base_uri "#{Giftrocket.config[:base_api_uri]}orders/"
6
-
7
- attr_accessor :id, :gifts, :payment, :sender
4
+ attr_accessor :id, :external_id, :gifts, :payment, :sender
8
5
 
9
6
  def initialize(attributes)
10
7
  attributes = attributes.with_indifferent_access
11
8
  self.id = attributes[:id]
9
+ self.external_id = attributes[:external_id]
12
10
  self.gifts = attributes[:gifts].map do |gift_attributes|
13
11
  Gift.new(gift_attributes)
14
12
  end
@@ -17,41 +15,37 @@ module Giftrocket
17
15
  self.sender = Giftrocket::User.new(attributes[:sender])
18
16
  end
19
17
 
20
- def self.create!(funding_source_id, gifts_data_array)
18
+ def self.create!(funding_source_id, gifts, external_id=nil, organization_id=nil)
21
19
  data_to_post = {
22
20
  funding_source_id: funding_source_id,
23
- gifts: gifts_data_array
21
+ external_id: external_id,
22
+ organization_id: organization_id,
23
+ gifts: gifts
24
24
  }.merge(Giftrocket.default_options)
25
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
26
+ response = Giftrocket::Request.post 'orders',
27
+ body: data_to_post.to_json,
28
+ headers: { 'Content-Type' => 'application/json' }
29
+
30
+ Giftrocket::Order.new(response[:order])
33
31
  end
34
32
 
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)
33
+ def self.list(filters={})
34
+ Giftrocket::Request.get(
35
+ 'orders',
36
+ query: filters.merge(Giftrocket.default_options),
37
+ format: 'json'
38
+ )[:orders].map do |order_attributes|
39
+ Giftrocket::Order.new(order_attributes)
44
40
  end
45
41
  end
46
42
 
47
43
  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
44
+ response = Giftrocket::Request.get "orders/#{id}",
45
+ query: Giftrocket.default_options,
46
+ format: 'json'
47
+
48
+ Giftrocket::Order.new(response[:order])
55
49
  end
56
50
  end
57
51
  end
@@ -0,0 +1,36 @@
1
+ module Giftrocket
2
+ class Organization
3
+
4
+ attr_accessor :id, :name, :website, :phone, :created_at, :config
5
+
6
+ def initialize(attributes)
7
+ attributes = attributes.with_indifferent_access
8
+ self.id = attributes[:id]
9
+ self.name = attributes[:name]
10
+ self.website = attributes[:website]
11
+ self.phone = attributes[:phone]
12
+ self.config = attributes[:config]
13
+ self.created_at = attributes[:created_at]
14
+ end
15
+
16
+ def self.create!(data)
17
+ response = Giftrocket::Request.post(
18
+ 'organizations',
19
+ body: data.merge(Giftrocket.default_options).to_json,
20
+ headers: { 'Content-Type' => 'application/json' }
21
+ )
22
+
23
+ Giftrocket::Organization.new(response[:organization])
24
+ end
25
+
26
+ def self.list
27
+ Giftrocket::Request.get(
28
+ 'organizations',
29
+ query: Giftrocket.default_options,
30
+ format: 'json'
31
+ )[:organizations].map do |org|
32
+ Giftrocket::Organization.new(org)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ module Giftrocket
2
+ class OrganizationMember
3
+
4
+ attr_accessor :id, :name, :email, :role, :invite_url
5
+
6
+ def initialize(attributes)
7
+ attributes = attributes.with_indifferent_access
8
+ self.id = attributes[:id]
9
+ self.name = attributes[:name]
10
+ self.email = attributes[:email]
11
+ self.role = attributes[:role]
12
+ self.invite_url = attributes[:invite_url]
13
+ end
14
+
15
+ def self.to_path(organization_id)
16
+ "organizations/#{organization_id}/members"
17
+ end
18
+
19
+ def self.create!(organization_id, data)
20
+ response = Giftrocket::Request.post(
21
+ to_path(organization_id),
22
+ body: data.merge(Giftrocket.default_options).to_json,
23
+ headers: { 'Content-Type' => 'application/json' }
24
+ )
25
+
26
+ Giftrocket::OrganizationMember.new(response[:member])
27
+ end
28
+
29
+ def self.list(organization_id)
30
+ Giftrocket::Request.get(
31
+ to_path(organization_id),
32
+ query: Giftrocket.default_options,
33
+ format: 'json'
34
+ )[:members].map do |member|
35
+ Giftrocket::OrganizationMember.new(member)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ module Giftrocket
2
+ class Request
3
+ def self.get(path, *opts)
4
+ handle_response(HTTParty.get(url(path), *opts))
5
+ end
6
+ def self.post(path, *opts)
7
+ handle_response(HTTParty.post(url(path), *opts))
8
+ end
9
+ def self.put(path, *opts)
10
+ handle_response(HTTParty.put(url(path), *opts))
11
+ end
12
+ def self.delete(path, *opts)
13
+ handle_response(HTTParty.delete(url(path), *opts))
14
+ end
15
+ def self.url(path, params={})
16
+ url = URI.join(Giftrocket.config[:base_api_uri], path)
17
+ end
18
+
19
+ def self.handle_response(response)
20
+ if response.success?
21
+ response_json = JSON.parse(response.body).with_indifferent_access
22
+ else
23
+ raise Giftrocket::Error.new(response)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,9 +1,6 @@
1
1
  module Giftrocket
2
2
  class Style
3
3
 
4
- include HTTParty
5
- base_uri "#{Giftrocket.config[:base_api_uri]}styles/"
6
-
7
4
  attr_accessor :id, :card
8
5
 
9
6
  def initialize(attributes)
@@ -16,15 +13,14 @@ module Giftrocket
16
13
  card && card[:url]
17
14
  end
18
15
 
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)
16
+ def self.list(filters={})
17
+ options = filters.merge(Giftrocket.default_options)
18
+ response = Giftrocket::Request.get 'styles',
19
+ query: options,
20
+ format: 'json'
21
+
22
+ response[:styles].map do |style_attributes|
23
+ Giftrocket::Style.new(style_attributes)
28
24
  end
29
25
  end
30
26
  end
@@ -1,3 +1,3 @@
1
1
  module Giftrocket
2
- VERSION = '0.1.6'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giftrocket_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GiftRocket
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,7 +128,10 @@ files:
128
128
  - lib/giftrocket/funding_source.rb
129
129
  - lib/giftrocket/gift.rb
130
130
  - lib/giftrocket/order.rb
131
+ - lib/giftrocket/organization.rb
132
+ - lib/giftrocket/organization_member.rb
131
133
  - lib/giftrocket/payment.rb
134
+ - lib/giftrocket/request.rb
132
135
  - lib/giftrocket/style.rb
133
136
  - lib/giftrocket/user.rb
134
137
  - lib/giftrocket/version.rb
@@ -152,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
155
  version: '0'
153
156
  requirements: []
154
157
  rubyforge_project:
155
- rubygems_version: 2.4.8
158
+ rubygems_version: 2.4.6
156
159
  signing_key:
157
160
  specification_version: 4
158
161
  summary: GiftRocket Ruby API SDK