spektrix 0.0.1 → 0.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75142429ee35e702751b0232e999e40c4b74eaa9
4
- data.tar.gz: 65db3438fe53e2d16d1faac76d479aec8c2a697c
3
+ metadata.gz: c78a69fb34e85fa562d264623827505560763571
4
+ data.tar.gz: c0c4fc02d52d08017a45281466e65b003b219657
5
5
  SHA512:
6
- metadata.gz: 02ab04c7ed14fc993da1e51a1818d071113e239d31e3e767a65793f90a1450fb05f7e96d25c0e901e7c505605380ab416045fad888c4d775229596fdfec0d270
7
- data.tar.gz: 28a70513c8d31ce64fd4714cfdcdc262a1fb338992881ae9c5a5107b42b84b5df765e3d4ca6aadca53fee91900e6c41cd2e24f7865c3881ab607ca1f9bc09c82
6
+ metadata.gz: ed31c5c8d6e1f0adad487a29405384b8d5025fb9cb113c4ba9dcbad35b6bb26b029a37d4651577f6049a81e218a5389a8d8a1a63b605da379e371e62be92a0f9
7
+ data.tar.gz: f9f2fade733a6c67306b706d427673c0dc4246f2ba7aa59a5a816786ee125851773949dca5c5c90c56c86ae2e835a50f7c4a6c23459659c78d302c1a9fb11389
data/README.md CHANGED
@@ -41,7 +41,7 @@ end
41
41
  # Use
42
42
 
43
43
  ## Events, instances and prices
44
- Events have instances, which in turn have seating plans and a price list. Seating plans aren't catered for, but bands and ticket types are.
44
+ Events have instances, which in turn have seating plans and a price list.
45
45
 
46
46
  ```
47
47
  include Spektrix #You don't have to do this, just prefix all the calls with `Spektrix::` otherwise
@@ -64,6 +64,9 @@ Spektrix::Tickets::Band.all #a collection of bands
64
64
  Spektrix::Tickets::PriceList.where(event_id: 123) #the prices for event 123, without calling the Event itself.
65
65
  ```
66
66
 
67
+ ## Custom Attributes
68
+ Spektrix allows you to set custom attributes for various objects. This library handles these automatically, and they're accessible as instance variables on your objects.
69
+
67
70
  # Contributing
68
71
  We'd love to have your input if you're making use of this:
69
72
 
@@ -11,6 +11,10 @@ module Spektrix
11
11
  Instance.where(event_id: self.id).to_a
12
12
  end
13
13
 
14
+ def title
15
+ name
16
+ end
17
+
14
18
  end
15
19
  end
16
20
  end
@@ -6,6 +6,7 @@ module Spektrix
6
6
  collection_path "instances"
7
7
 
8
8
  after_find ->(r) do
9
+ # parse times
9
10
  [:start,
10
11
  :start_utc,
11
12
  :start_selling_at,
@@ -24,15 +25,24 @@ module Spektrix
24
25
  r.send(:"#{field}=",time)
25
26
  end
26
27
  end
28
+
29
+ # we make price_list an actual Spektrix::Tickets:PriceList, but keep the original for reference
30
+ r.price_list_id = r.price_list[:id].to_i
31
+
27
32
  end
28
33
 
29
34
  def status
30
35
  InstanceStatus.where(instance_id: self.id).first
31
36
  end
32
37
 
33
- def prices
34
- Tickets::PriceList.where(instance_id: self.id).first.prices
38
+ def price_list
39
+ Tickets::PriceList.where(instance_id: self.id).first
35
40
  end
41
+
42
+ def event_object
43
+ Event.where(event_id: event[:id]).first
44
+ end
45
+
36
46
  end
37
47
  end
38
48
  end
@@ -4,6 +4,18 @@ module Spektrix
4
4
  include Spektrix::Base
5
5
  collection_path "plans"
6
6
 
7
+ def to_s
8
+ name
9
+ end
10
+
11
+ def all
12
+ @all ||= all(all: true)
13
+ end
14
+
15
+ # The API doesn't allow you to filter by band_id, so we get all and find() in ruby
16
+ def self.find(id)
17
+ all.to_a.find {|b| b.id.to_i == id}
18
+ end
7
19
 
8
20
  end
9
21
  end
@@ -7,6 +7,11 @@ module Spektrix
7
7
  def to_s
8
8
  self.name
9
9
  end
10
+
11
+ # The API doesn't allow you to filter by band_id, so we get all and find() in ruby
12
+ def self.find(id)
13
+ all.to_a.find {|b| b.id.to_i == id}
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -1,6 +1,6 @@
1
1
  module Spektrix
2
2
  module Tickets
3
- class Price < OpenStruct
3
+ class Price < ::OpenStruct
4
4
 
5
5
  end
6
6
  end
@@ -5,16 +5,26 @@ module Spektrix
5
5
  collection_path "price-lists"
6
6
 
7
7
  after_find ->(r) do
8
- bands = Band.all.to_a
9
- ticket_types = Type.all.to_a
8
+ @@bands ||= Band.all.to_a
9
+ @@ticket_types ||= Type.all.to_a
10
10
  if r.respond_to?(:price)
11
+ r.price = [r.price] unless r.price.is_a?(Array)
11
12
  r.prices = r.price.collect do |price|
12
- price[:band] = bands.find {|b| b.id == price[:band][:id]}
13
- price[:ticket_type] = ticket_types.find {|t| t.id == price[:ticket_type][:id]}
13
+ price[:band] = @@bands.find {|b| b.id == price[:band][:id]}
14
+ price[:ticket_type] = @@ticket_types.find {|t| t.id == price[:ticket_type][:id]}
14
15
  Price.new(price)
15
16
  end
16
17
  end
17
18
  end
19
+
20
+ def self.find(id)
21
+ all.to_a.find {|r| r.id.to_i == id }
22
+ end
23
+
24
+
25
+
26
+
18
27
  end
19
28
  end
20
- end
29
+ end
30
+
@@ -6,7 +6,7 @@ require_rel '.'
6
6
  class Hash; include DeepSymbolizable; end
7
7
  module Spektrix
8
8
  class << self
9
- attr_accessor :configuration
9
+ attr_accessor :configuration, :debug_request
10
10
  end
11
11
 
12
12
  def self.configure
@@ -22,7 +22,8 @@ module Spektrix
22
22
  :api_key, #the key you get from the spektrix interface.
23
23
  :proxy, #note that proxying requests with a client cert might break some stuff.
24
24
  :base_url,
25
- :api_path
25
+ :api_path,
26
+ :logger
26
27
 
27
28
  attr_reader :connection,
28
29
  :ssl_options
@@ -60,6 +61,12 @@ module Spektrix
60
61
 
61
62
  @connection.setup url: @connection_path, ssl: @ssl_options, proxy: @proxy do |c|
62
63
 
64
+ if @logger
65
+ #Connection Debugging
66
+ c.use Spektrix::DebugMiddleware, @logger
67
+ end
68
+
69
+
63
70
  #Api Auth
64
71
  c.params[:api_key] = @api_key
65
72
 
@@ -29,6 +29,11 @@ module Spektrix
29
29
  where("#{entity_name}_id" => id).first
30
30
  end
31
31
 
32
+ # 'all' needs to have a querystring param passed to really get all
33
+ def all(args = {})
34
+ super({all: true}.merge(args))
35
+ end
36
+
32
37
  # Get the entity name; used in other places (like find())
33
38
  # @return [String] the entity name
34
39
  def entity_name
@@ -0,0 +1,50 @@
1
+ # Code courtesty https://github.com/envylabs/faraday-detailed_logger - MIT licence
2
+
3
+ module Spektrix
4
+ class DebugMiddleware < Faraday::Response::Middleware
5
+
6
+ def self.default_logger
7
+ require "logger"
8
+ ::Logger.new(STDOUT)
9
+ end
10
+
11
+ # Public: Initialize a new Logger middleware.
12
+ #
13
+ # app - A Faraday-compatible middleware stack or application.
14
+ # logger - A Logger-compatible object to which the log information will
15
+ # be recorded.
16
+ # progname - A String containing a program name to use when logging.
17
+ #
18
+ # Returns a Logger instance.
19
+ #
20
+ def initialize(app, logger = nil, progname = nil)
21
+ super(app)
22
+ @logger = logger || self.class.default_logger
23
+ @progname = progname
24
+ end
25
+
26
+ # Public: Used by Faraday to execute the middleware during the
27
+ # request/response cycle.
28
+ #
29
+ # env - A Faraday-compatible request environment.
30
+ #
31
+ # Returns the result of the parent application execution.
32
+ #
33
+ def call(env)
34
+ if Spektrix.debug_request
35
+ @logger.info(@progname) { "#{env[:method].upcase} #{env[:url]}" }
36
+ @logger.debug(@progname) { curl_output(env[:request_headers], env[:body]).inspect }
37
+ end
38
+
39
+ super
40
+ end
41
+
42
+ private
43
+ def curl_output(headers, body)
44
+ string = headers.collect { |k,v| "#{k}: #{v}" }.join("\n")
45
+ string + "\n\n#{body}"
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Spektrix
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2.1"
3
3
  end
@@ -23,7 +23,5 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "her", "~> 0.8"
25
25
  spec.add_dependency "require_all", "~> 1.3"
26
- # spec.add_dependency "multi_xml", "~> 0.5"
27
- # spec.add_dependency "faraday_middleware", "~> 0.10"
28
26
  spec.add_dependency "nokogiri"
29
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spektrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Jones
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-18 00:00:00.000000000 Z
12
+ date: 2016-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -105,6 +105,7 @@ files:
105
105
  - lib/models/tickets/type.rb
106
106
  - lib/spektrix.rb
107
107
  - lib/spektrix/base.rb
108
+ - lib/spektrix/debug_middleware.rb
108
109
  - lib/spektrix/deep_symbolize.rb
109
110
  - lib/spektrix/response_parser.rb
110
111
  - lib/spektrix/version.rb