centaman 5.0.3 → 5.0.4

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
  SHA256:
3
- metadata.gz: 7c7e0b74f83cf29c8b7538e6da0db66f662bc45aab23f981e0af149d2ff28e78
4
- data.tar.gz: 8a114ee36ae2a275aaa9f5c1e652f0b12c6c7bb174bb6aca22c70f95ea853403
3
+ metadata.gz: a516b332a9ca51cb83da3ffd9d9de78e38625dc27704813165e10a0d7ef711f7
4
+ data.tar.gz: 5e01b2f1771df4f856f42fda69d8b048a2e474c4f521103f8497807d7b90829f
5
5
  SHA512:
6
- metadata.gz: ef044272a2a7afdaf8b63e12f143567c2f4ffc0cdbbdb94eb47a57bd8d1e15834f38d8224f2af96b404db9a90442d71bdf1cfa9af2457e301cfdf31bdaea0530
7
- data.tar.gz: 88ee3afa86e3e55ed71e6ce9e6cf061175a3e5310f6be527cc652184ef8f7902a0e72fc1ec00e8c73de84e6012ed9ee172ea51074757425d4c7369f042b093d2
6
+ metadata.gz: b88526829eb9a3ddeac10ea782cd7b0024bd69f8bcdd6747f9fe5efc88dd0c45fa90fbedbe8348247fe313ba43bf16a9706f86a2cf1a5e08e9d3a136f67a8130
7
+ data.tar.gz: d7c67e8abb8d75d1f6139f2ee5af4c5cf9e5f49f8945b42758b9f1543c0a185f975074c6271db3bc9d17907fcc1bf8d0cc57e2a2722cb3f18bef253f1aef48c6
@@ -41,6 +41,16 @@ require 'centaman/object/membership_type'
41
41
  require 'centaman/object/add_on'
42
42
  require 'centaman/object/purchased_ticket'
43
43
  require 'centaman/object/ticket_type'
44
+ require 'centaman/configuration'
44
45
 
45
46
  module Centaman
47
+ class << self
48
+ def configuration
49
+ @config ||= Centaman::Configuration.new
50
+ end
51
+
52
+ def config
53
+ yield configuration
54
+ end
55
+ end
46
56
  end
@@ -0,0 +1,9 @@
1
+ module Centaman
2
+ class Configuration
3
+ attr_accessor :object_overrides
4
+
5
+ def initialize
6
+ @object_overrides = {}
7
+ end
8
+ end
9
+ end
@@ -9,14 +9,14 @@ module Centaman
9
9
  def build_objects(resp)
10
10
  return [] unless resp.respond_to?(:map)
11
11
  @tickets = resp.map do |ticket_hash|
12
- object_class.new(ticket_hash.merge(additional_hash_to_serialize_after_response))
12
+ final_object_class.new(ticket_hash.merge(additional_hash_to_serialize_after_response))
13
13
  end
14
14
  end
15
15
 
16
16
  # i.e. from GET of a show or POST
17
17
  def build_object(resp)
18
18
  return resp unless resp.respond_to?(:merge)
19
- @build_object ||= object_class.new(resp.merge(additional_hash_to_serialize_after_response))
19
+ @build_object ||= final_object_class.new(resp.merge(additional_hash_to_serialize_after_response))
20
20
  end
21
21
 
22
22
  def additional_hash_to_serialize_after_response
@@ -26,5 +26,12 @@ module Centaman
26
26
  def object_class
27
27
  raise "object_class is required for #{self.class.name}"
28
28
  end
29
+
30
+ def final_object_class
31
+ name = self.class.name.split('::').last
32
+ override = Centaman.configuration.object_overrides[name]
33
+ override_class = override.constantize if override
34
+ override_class || object_class
35
+ end
29
36
  end
30
37
  end
@@ -1,32 +1,14 @@
1
- require 'timeout'
2
-
3
1
  module Centaman
4
2
  #:nodoc:
5
3
  class Service < Wrapper
6
- DEFAULT_TIMEOUT_TIME = 15
7
-
8
4
  def after_init(args)
9
5
  # overwritten by subclasses
10
6
  end
11
7
 
12
- def wrap_request_in_case_of_timeout(proc, options = {})
13
- time = options.fetch(:timeout_time, DEFAULT_TIMEOUT_TIME)
14
- resp = nil
15
- begin
16
- resp = Timeout.timeout(time) do
17
- proc.call
18
- end
19
- rescue Timeout::Error
20
- p "*** CENTAMAN GEM TIMEOUT ***"
21
- raise Exceptions::CentamanTimeout
22
- end
23
- resp
24
- end
25
-
26
8
  def fetch_all
27
9
  @get_request ||= begin
28
10
  req = Proc.new do
29
- self.class.get(endpoint, payload(:get))
11
+ self.class.get("#{api_url}#{endpoint}", payload(:get))
30
12
  end
31
13
  resp = wrap_request_in_case_of_timeout(req, timeout_time: 20)
32
14
 
@@ -39,7 +21,7 @@ module Centaman
39
21
  def post
40
22
  @post_request ||= begin
41
23
  req = Proc.new do
42
- self.class.post(endpoint, payload(:post))
24
+ self.class.post("#{api_url}#{endpoint}", payload(:post))
43
25
  end
44
26
  resp = wrap_request_in_case_of_timeout(req)
45
27
  self.respond_to?(:build_object) ? after_post(resp) : resp
@@ -49,7 +31,7 @@ module Centaman
49
31
  def put
50
32
  @put_request ||= begin
51
33
  req = Proc.new do
52
- self.class.put(endpoint, payload(:put))
34
+ self.class.put("#{api_url}#{endpoint}", payload(:put))
53
35
  end
54
36
  resp = wrap_request_in_case_of_timeout(req)
55
37
  self.respond_to?(:build_object) ? after_post(resp) : resp
@@ -59,14 +41,5 @@ module Centaman
59
41
  def after_post(response)
60
42
  build_object(response)
61
43
  end
62
-
63
- def payload(request_type = :get)
64
- hash = { payload_key(request_type) => options_hash }
65
- hash.merge(headers: headers)
66
- end
67
-
68
- def payload_key(request_type)
69
- request_type == :get ? :query : :body
70
- end
71
44
  end
72
45
  end
@@ -1,3 +1,3 @@
1
1
  module Centaman
2
- VERSION = "5.0.3"
2
+ VERSION = "5.0.4"
3
3
  end
@@ -1,20 +1,28 @@
1
+ require 'timeout'
2
+
1
3
  module Centaman
2
4
  #:nodoc:
3
5
  class Wrapper
6
+ DEFAULT_TIMEOUT_TIME = 15
4
7
  include HTTParty
5
8
 
6
- if ENV['FIXIE_URL']
7
- FIXIE = URI.parse(ENV['FIXIE_URL'])
8
- http_proxy FIXIE.host, FIXIE.port, FIXIE.user, FIXIE.password
9
- end
10
-
11
- attr_reader :api_username, :api_password, :api_token
9
+ attr_reader :api_username, :api_password, :api_token, :api_url,
10
+ :proxie_host, :proxie_port, :proxie_user, :proxie_password
12
11
 
13
12
  def initialize(args = {})
14
- @api_username = ENV['CENTAMAN_API_USERNAME']
15
- @api_password = ENV['CENTAMAN_API_PASSWORD']
16
- @api_token = ENV.fetch('CENTAMAN_API_TOKEN', generate_token)
17
- self.class.base_uri ENV['CENTAMAN_API_URL']
13
+ # required
14
+ @api_username = args.fetch(:api_username) { ENV['CENTAMAN_API_USERNAME'] }
15
+ @api_password = args.fetch(:api_password) { ENV['CENTAMAN_API_PASSWORD'] }
16
+ @api_url = args.fetch(:api_url) { ENV['CENTAMAN_API_URL'] }
17
+
18
+ # optional
19
+ @api_token = args.fetch(:api_token) { ENV['CENTAMAN_API_TOKEN'] || generate_token }
20
+ fixie_url = args.fetch(:fixie_url) { ENV['FIXIE_URL'] }
21
+ fixie = fixie_url ? URI.parse(fixie_url) : nil
22
+ @proxie_host = args.fetch(:proxie_host) { fixie.try(:host) }
23
+ @proxie_port = args.fetch(:proxie_port) { fixie.try(:port) }
24
+ @proxie_user = args.fetch(:proxie_user) { fixie.try(:user) }
25
+ @proxie_password = args.fetch(:proxie_password) { fixie.try(:password) }
18
26
  after_init(args)
19
27
  end
20
28
 
@@ -42,5 +50,38 @@ module Centaman
42
50
  def after_init(args = {})
43
51
  # hook method for subclasses
44
52
  end
53
+
54
+ def payload(request_type = :get)
55
+ hash = { payload_key(request_type) => options_hash }
56
+ hash.merge(headers: headers).merge(proxy_hash)
57
+ end
58
+
59
+ def payload_key(request_type)
60
+ request_type == :get ? :query : :body
61
+ end
62
+
63
+ def proxy_hash
64
+ return {} unless proxie_host
65
+ {
66
+ http_proxyaddr: proxie_host,
67
+ http_proxyport: proxie_port,
68
+ http_proxyuser: proxie_user,
69
+ http_proxypass: proxie_password,
70
+ }
71
+ end
72
+
73
+ def wrap_request_in_case_of_timeout(proc, options = {})
74
+ time = options.fetch(:timeout_time, DEFAULT_TIMEOUT_TIME)
75
+ resp = nil
76
+ begin
77
+ resp = Timeout.timeout(time) do
78
+ proc.call
79
+ end
80
+ rescue Timeout::Error
81
+ p "*** CENTAMAN GEM TIMEOUT ***"
82
+ raise Exceptions::CentamanTimeout
83
+ end
84
+ resp
85
+ end
45
86
  end
46
87
  end
@@ -0,0 +1,13 @@
1
+ module Centaman
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc "Creates a Centaman initializer in your application."
7
+
8
+ def copy_initializer
9
+ copy_file "initializer.rb", "config/initializers/centaman.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ Centaman.config do |config|
2
+ # { 'GeneralAdmissionTicket' => 'CentamanExt::Object::GeneralAdmissionTicket' }
3
+ config.object_overrides = {}
4
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centaman
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.3
4
+ version: 5.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - francirp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-05-17 00:00:00.000000000 Z
12
+ date: 2018-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -88,6 +88,7 @@ files:
88
88
  - dump.rdb
89
89
  - lib/centaman.rb
90
90
  - lib/centaman/attribute.rb
91
+ - lib/centaman/configuration.rb
91
92
  - lib/centaman/exceptions.rb
92
93
  - lib/centaman/filter.rb
93
94
  - lib/centaman/json_wrapper.rb
@@ -129,6 +130,8 @@ files:
129
130
  - lib/centaman/service/update_member.rb
130
131
  - lib/centaman/version.rb
131
132
  - lib/centaman/wrapper.rb
133
+ - lib/generators/centaman/install_generator.rb
134
+ - lib/generators/centaman/templates/initializer.rb
132
135
  homepage: https://github.com/LaunchPadLab/centaman
133
136
  licenses:
134
137
  - MIT