tickethub 0.0.2 → 0.0.3

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: e9b17caefcb50ec0f515e5353ed3b1e6b5482a9e
4
- data.tar.gz: a7c2ffbe9f3bf76390cf4f91537938dd291e01c1
3
+ metadata.gz: ccb152a358383394fb8a2903b7cf8355371fb8d7
4
+ data.tar.gz: 828a41238c5ab820f77bcdf4348b54c177360c89
5
5
  SHA512:
6
- metadata.gz: aae62d812c0fa09ccf4f8047dc61868b835358e94ee81fc4c7ab4e77b514b033d5a5dca54e8788249e89db8f5e3ec4975435d866310e0a3de4f12e98dbf817fb
7
- data.tar.gz: d1bdccf887031cc948ec303fce72c2f08fb1a26a5d4982a2f38a4ae8a82e1963e8788758dc6638ea464838c0dfa2c2761c851fe77380ca04aa5e9da15ecb0238
6
+ metadata.gz: e9812ade047a542884babf81062e6dc99974d101b10ece33b5a8ccbb6279eba62a0d9e8de576bffb37f01173b3568b3ae4d6e88fa7275dc0bd14d4f655f5d341
7
+ data.tar.gz: d194028938875dda6266b94883f92e948114abf244e36aefa3758d2ad56068382425f36fe51e51221124976a4892d0fb03a5b286d663e9bfeeaf9d6267147b3f
@@ -137,9 +137,9 @@ module Tickethub
137
137
  end
138
138
 
139
139
  def create(attributes = {})
140
- @klass.new @endpoint, @endpoint.post(attributes).decoded
140
+ @klass.load @endpoint, @endpoint.post(attributes).decoded
141
141
  rescue Tickethub::ResourceInvalid => err
142
- @klass.new @endpoint, Tickethub::Response.new(err.response).decoded
142
+ @klass.load @endpoint, Tickethub::Response.new(err.response).decoded
143
143
  end
144
144
 
145
145
  def scope(key, params = {}, options = {})
@@ -10,16 +10,13 @@ module Tickethub
10
10
 
11
11
  class << self
12
12
 
13
- def all(params = {})
14
- Tickethub::Collection.new @endpoint, self, params
15
- end
16
-
17
- def polymorphic(type, options = {})
18
- self.superclass.register_type type, **options
13
+ def path(value, options = {})
14
+ @path = value
15
+ @options = options
19
16
  end
20
17
 
21
- def register_type(type, klass: self, attribute: :type) # klass, attribute
22
- registered_types[type] = { klass: klass, attribute: attribute }
18
+ def endpoint
19
+ Tickethub.endpoint[@path, @options]
23
20
  end
24
21
 
25
22
  def registered_types
@@ -30,150 +27,163 @@ module Tickethub
30
27
  @scopes ||= {}
31
28
  end
32
29
 
33
- def path(value, options = {})
34
- @singleton = options.delete(:singleton) || false
35
- @path = value
36
- @options = options
30
+ def attributes
31
+ @attributes ||= {}
37
32
  end
38
33
 
39
- def endpoint
40
- Tickethub.endpoint[@path, @options]
34
+ def descendants
35
+ @descendants ||= []
41
36
  end
37
+ end
42
38
 
43
- def scope(key, proc = -> (params = {}) { self.scope key, params })
44
- self.scopes[key] = proc
39
+ def self.inherited(descendant)
40
+ if descendant.ancestors.member? Tickethub::Resource
41
+ self.descendants.push descendant
45
42
  end
43
+ end
46
44
 
47
- def singleton?
48
- !! @singleton
49
- end
45
+ def self.all(params = {})
46
+ Tickethub::Collection.new self.endpoint, self, params
47
+ end
50
48
 
51
- def attribute(key, options = nil)
52
- options.nil?? (self.attributes[key] ||= {}).dup
53
- : self.attributes[key] = options
54
- end
49
+ def self.polymorphic(type, attribute = :type)
50
+ self.superclass.register_type type, self, attribute
51
+ end
55
52
 
56
- def attributes
57
- @attributes ||= {}
58
- end
53
+ def self.register_type(type, klass, attribute = :type) # klass, attribute
54
+ self.registered_types[type] = { klass: klass, attribute: attribute }
55
+ end
59
56
 
60
- def load_value(key, value, object)
61
- return nil if value.nil? || (value.is_a?(String) && value.empty?)
62
- case self.attribute(key)[:type]
63
- when :date
64
- case value
65
- when String then ISO8601::Date.new(value)
66
- else raise ArgumentError, 'invalid date value: ' + value
67
- end
68
- when :datetime
69
- case value
70
- when String then ISO8601::DateTime.new(value)
71
- else raise ArgumentError, 'invalid datetime value: ' + value
72
- end
73
- when :time
74
- case value
75
- when String then ISO8601::Time.new(value)
76
- else raise ArgumentError, 'invalid time value: ' + value
77
- end
78
- when :duration
79
- case value
80
- when String then ISO8601::Duration.new(value)
81
- else raise ArgumentError, 'invalid time value: ' + value
82
- end
83
- when :money
84
- currency = Money::Currency.new(object.currency)
85
- raise ArgumentError, 'invalid money currency' if currency.blank?
86
-
87
- case value
88
- when Fixnum then Money.new(value, currency)
89
- when Numeric, String
90
- currency = Money::Currency.wrap(currency)
91
- Money.new(value.to_d * currency.subunit_to_unit, currency)
92
- else raise ArgumentError, 'invalid money value: ' + value
93
- end
94
- when :currency
95
- case value
96
- when String then Money::Currency.new(value)
97
- else raise ArgumentError, 'invalid currency value: ' + value
98
- end
99
- when :timezone
100
- case value
101
- when String then Timezone::Zone.new(zone: value)
102
- else raise ArgumentError, 'invalid timezone value: ' + value
103
- end
104
- when :country
105
- case value
106
- when String then Country.new(value)
107
- else raise ArgumentError, 'invalid country value: ' + value
108
- end
109
- else value
110
- end
57
+ def self.attribute(key, options)
58
+ self.attributes[key] = options
59
+
60
+ self.descendants.each do |descendant|
61
+ descendant.attributes[key] = options
111
62
  end
63
+ end
112
64
 
113
- def dump_value(key, value)
114
- case self.attribute(key)[:type]
115
- when :date then value.iso8601
116
- when :datetime then value.iso8601
117
- when :time then value.iso8601[10..-1]
118
- when :duration then value.iso8601
119
- when :money then value.fractional
120
- when :timezone then value.zone
121
- when :country then value.alpha2
122
- when :currency then value.iso_code
123
- else value
124
- end
65
+ def self.scope(key, proc = -> (params = {}) { self.scope key, params })
66
+ self.scopes[key] = proc
67
+ end
68
+
69
+ def self.load_value(key, value, object)
70
+ return nil if value.nil? || (value.is_a?(String) && value.empty?)
71
+ return value unless self.attributes.key? key
72
+
73
+ case self.attributes[key][:type]
74
+ when :date
75
+ case value
76
+ when String then ISO8601::Date.new(value)
77
+ else raise ArgumentError, 'invalid date value: ' + value
78
+ end
79
+ when :datetime
80
+ case value
81
+ when String then ISO8601::DateTime.new(value)
82
+ else raise ArgumentError, 'invalid datetime value: ' + value
83
+ end
84
+ when :time
85
+ case value
86
+ when String then ISO8601::Time.new(value)
87
+ else raise ArgumentError, 'invalid time value: ' + value
88
+ end
89
+ when :duration
90
+ case value
91
+ when String then ISO8601::Duration.new(value)
92
+ else raise ArgumentError, 'invalid time value: ' + value
93
+ end
94
+ when :money
95
+ currency = Money::Currency.new(object.currency)
96
+ raise ArgumentError, 'invalid money currency' if currency.blank?
97
+
98
+ case value
99
+ when Fixnum then Money.new(value, currency)
100
+ when Numeric, String
101
+ currency = Money::Currency.wrap(currency)
102
+ Money.new(value.to_d * currency.subunit_to_unit, currency)
103
+ else raise ArgumentError, 'invalid money value: ' + value
104
+ end
105
+ when :currency
106
+ case value
107
+ when String then Money::Currency.new(value)
108
+ else raise ArgumentError, 'invalid currency value: ' + value
109
+ end
110
+ when :timezone
111
+ case value
112
+ when String then Timezone::Zone.new(zone: value)
113
+ else raise ArgumentError, 'invalid timezone value: ' + value
114
+ end
115
+ when :country
116
+ case value
117
+ when String then Country.new(value)
118
+ else raise ArgumentError, 'invalid country value: ' + value
119
+ end
120
+ else value
125
121
  end
122
+ end
126
123
 
127
- def serialize(attributes)
128
- attributes.collect do |key, value|
129
- [key, dump_value(key, value)]
130
- end.to_h
124
+ def self.dump_value(key, value)
125
+ return value unless self.attributes.key? key
126
+ case self.attributes[key][:type]
127
+ when :date then value.iso8601
128
+ when :datetime then value.iso8601
129
+ when :time then value.iso8601[10..-1]
130
+ when :duration then value.iso8601
131
+ when :money then value.fractional
132
+ when :timezone then value.zone
133
+ when :country then value.alpha2
134
+ when :currency then value.iso_code
135
+ else value
131
136
  end
137
+ end
132
138
 
133
- def load(endpoint, attributes = nil)
134
- attributes ||= endpoint.get
139
+ def self.serialize(attributes)
140
+ attributes.collect do |key, value|
141
+ [key, dump_value(key, value)]
142
+ end.to_h
143
+ end
135
144
 
136
- klass = registered_types.find do |type, options|
137
- attributes[options[:attribute].to_s] == type
138
- end
145
+ def self.load(endpoint, attributes = nil)
146
+ attributes ||= endpoint.get
139
147
 
140
- klass = klass ? klass[1][:klass] : self
148
+ klass = registered_types.find do |type, options|
149
+ attributes[options[:attribute].to_s] == type
150
+ end
141
151
 
142
- if id = attributes['id']
143
- endpoint = klass.endpoint[id, endpoint.options]
144
- end
152
+ klass = klass ? klass[1][:klass] : self
145
153
 
146
- klass.new endpoint, attributes
154
+ if id = attributes['id']
155
+ endpoint = klass.endpoint[id, endpoint.options]
147
156
  end
148
157
 
149
- def association(key, klass, path: key)
150
- define_method key do
151
- instance_variable_defined?("@#{key}") ? instance_variable_get("@#{key}") :
152
- instance_variable_set("@#{key}", klass.load(@endpoint[path]))
153
- end
158
+ klass.new endpoint, attributes
159
+ end
154
160
 
155
- define_method "#{key}=" do |value|
156
- instance_variable_set "@#{key}", ((value.nil? || value.is_a?(klass)) ? value :
157
- klass.load(@endpoint[path], value))
158
- end
161
+ def self.association(key, klass, path: key)
162
+ define_method key do
163
+ instance_variable_defined?("@#{key}") ? instance_variable_get("@#{key}") :
164
+ instance_variable_set("@#{key}", klass.load(@endpoint[path]))
159
165
  end
160
166
 
161
- def collection(key, klass, path: key, &block)
167
+ define_method "#{key}=" do |value|
168
+ instance_variable_set "@#{key}", ((value.nil? || value.is_a?(klass)) ? value :
169
+ klass.load(@endpoint[path], value))
170
+ end
171
+ end
162
172
 
163
- define_method key do |params = {}|
164
- (instance_variable_defined?("@#{key}") ? instance_variable_get("@#{key}") :
165
- (sinleton? || id?) ? instance_variable_set("@#{key}",
166
- Tickethub::Collection.new(@endpoint[path], klass, params)) : []).tap do |collection|
167
- collection.instance_eval &block if block
168
- end
169
- end
173
+ def self.collection(key, klass, path: key, &block)
174
+ define_method key do |params = {}|
175
+ (instance_variable_defined?("@#{key}") ? instance_variable_get("@#{key}") :
176
+ (sinleton? || id?) ? instance_variable_set("@#{key}",
177
+ Tickethub::Collection.new(@endpoint[path], klass, params)) : []).tap do |collection|
178
+ collection.instance_eval &block if block
179
+ end
180
+ end
170
181
 
171
- define_method "#{key}=" do |values|
172
- instance_variable_set "@#{key}", (singleton? || id?) ?
173
- (Tickethub::Collection.new(@endpoint[path], klass).tap do |collection|
174
- collection.cache = values
175
- end) : values.collect { |value| klass.load @endpoint, value }
176
- end
182
+ define_method "#{key}=" do |values|
183
+ instance_variable_set "@#{key}", id??
184
+ (Tickethub::Collection.new(@endpoint[path], klass).tap do |collection|
185
+ collection.cache = values
186
+ end) : values.collect { |value| klass.load @endpoint, value }
177
187
  end
178
188
  end
179
189
 
@@ -202,10 +212,6 @@ module Tickethub
202
212
  self.load @endpoint.delete.decoded
203
213
  end
204
214
 
205
- def singleton?
206
- !! @singleton
207
- end
208
-
209
215
  def respond_to?(method, include_priv = false)
210
216
  @attributes.key?(method.to_s.remove(/[=\?]\Z/).to_sym) || super
211
217
  end
@@ -2,7 +2,7 @@ require_relative '../message'
2
2
 
3
3
  module Tickethub
4
4
  class Supplier::Message::Email < Supplier::Message
5
- polymorphic 'email', attribute: :type
5
+ polymorphic 'email'
6
6
  path '/supplier/messages/email'
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ require_relative '../message'
2
2
 
3
3
  module Tickethub
4
4
  class Supplier::Message::SMS < Supplier::Message
5
- polymorphic 'sms', attribute: :type
5
+ polymorphic 'sms'
6
6
  path '/supplier/messages/sms'
7
7
  end
8
8
  end
@@ -2,17 +2,13 @@ require_relative '../payment'
2
2
 
3
3
  module Tickethub
4
4
  class Supplier::Payment::Card < Supplier::Payment
5
- polymorphic 'card', attribute: :type
5
+ polymorphic 'card'
6
6
  path '/supplier/payments/card'
7
7
 
8
8
  require_relative '../card'
9
- require_relative '../gateway'
10
-
11
9
  require_relative '../../address'
12
10
 
13
11
  association :card, Supplier::Card
14
- association :gateway, Supplier::Gateway
15
-
16
12
  association :address, Tickethub::Address
17
13
  end
18
14
  end
@@ -2,7 +2,7 @@ require_relative '../payment'
2
2
 
3
3
  module Tickethub
4
4
  class Supplier::Payment::Cash < Supplier::Payment
5
- polymorphic 'cash', attribute: :type
5
+ polymorphic 'cash'
6
6
  path '/supplier/payments/cash'
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ require_relative '../payment'
2
2
 
3
3
  module Tickethub
4
4
  class Supplier::Payment::Credit < Supplier::Payment
5
- polymorphic 'credit', attribute: :type
5
+ polymorphic 'credit'
6
6
  path '/supplier/payments/credit'
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ require_relative '../payment'
2
2
 
3
3
  module Tickethub
4
4
  class Supplier::Payment::Direct < Supplier::Payment
5
- polymorphic 'direct', attribute: :type
5
+ polymorphic 'direct'
6
6
  path '/supplier/payments/direct'
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ require_relative '../payment'
2
2
 
3
3
  module Tickethub
4
4
  class Supplier::Payment::Gratuity < Supplier::Payment
5
- polymorphic 'gratuity', attribute: :type
5
+ polymorphic 'gratuity'
6
6
  path '/supplier/payments/gratuity'
7
7
  end
8
8
  end
@@ -1,9 +1,8 @@
1
1
  module Tickethub
2
2
  class Supplier < Resource
3
- path '/supplier', singleton: true
3
+ path '/supplier'
4
4
 
5
5
  require_relative 'supplier/bill'
6
- require_relative 'supplier/gateway'
7
6
  require_relative 'supplier/customer'
8
7
  require_relative 'supplier/template'
9
8
  require_relative 'supplier/order'
@@ -31,7 +30,6 @@ module Tickethub
31
30
  require_relative 'token'
32
31
 
33
32
  collection :bills, Bill
34
- collection :gateways, Gateway
35
33
  collection :customers, Customer
36
34
  collection :templates, Template
37
35
  collection :orders, Order
@@ -80,7 +78,7 @@ module Tickethub
80
78
  end
81
79
 
82
80
  def settings
83
- @endpoint[:settings].get
81
+ @endpoint[:settings].get.decoded
84
82
  end
85
83
  end
86
84
  end
@@ -1,6 +1,6 @@
1
1
  module Tickethub
2
2
  class Token < Resource
3
- path '/token', singleton: true
3
+ path '/token'
4
4
 
5
5
  def can?(scope)
6
6
  self.scope.member? scope.to_s
@@ -1,6 +1,6 @@
1
1
  module Tickethub
2
2
  class User < Resource
3
- path '/user', singleton: true
3
+ path '/user'
4
4
 
5
5
  require_relative 'user/app'
6
6
  require_relative 'user/supplier'
@@ -1,3 +1,3 @@
1
1
  module Tickethub
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tickethub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,11 +143,6 @@ files:
143
143
  - lib/tickethub/supplier/customer.rb
144
144
  - lib/tickethub/supplier/element.rb
145
145
  - lib/tickethub/supplier/fee.rb
146
- - lib/tickethub/supplier/gateway.rb
147
- - lib/tickethub/supplier/gateway/handpoint.rb
148
- - lib/tickethub/supplier/gateway/ideal.rb
149
- - lib/tickethub/supplier/gateway/paypal.rb
150
- - lib/tickethub/supplier/gateway/stripe.rb
151
146
  - lib/tickethub/supplier/invoice.rb
152
147
  - lib/tickethub/supplier/message.rb
153
148
  - lib/tickethub/supplier/message/email.rb
@@ -1,8 +0,0 @@
1
- require_relative '../gateway'
2
-
3
- module Tickethub
4
- class Supplier::Gateway::Handpoint < Supplier::Gateway
5
- polymorphic 'handpoint', attribute: :type
6
- path '/supplier/gateways/handpoint'
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require_relative '../gateway'
2
-
3
- module Tickethub
4
- class Supplier::Gateway::Ideal < Supplier::Gateway
5
- polymorphic 'ideal', attribute: :type
6
- path '/supplier/gateways/ideal'
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require_relative '../gateway'
2
-
3
- module Tickethub
4
- class Supplier::Gateway::Paypal < Supplier::Gateway
5
- polymorphic 'paypal', attribute: :type
6
- path '/supplier/gateways/paypal'
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require_relative '../gateway'
2
-
3
- module Tickethub
4
- class Supplier::Gateway::Stripe < Supplier::Gateway
5
- polymorphic 'stripe', attribute: :type
6
- path '/supplier/gateways/stripe'
7
- end
8
- end
@@ -1,16 +0,0 @@
1
- require_relative '../resource'
2
-
3
- module Tickethub
4
- class Supplier::Gateway < Resource
5
- path '/supplier/gateways'
6
-
7
- require_relative 'gateway/stripe'
8
- require_relative 'gateway/paypal'
9
- require_relative 'gateway/handpoint'
10
- require_relative 'gateway/ideal'
11
-
12
- require_relative 'payment'
13
-
14
- collection :payments, Supplier::Payment
15
- end
16
- end