spektrix 0.0.1 → 0.0.2.1
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 +4 -4
- data/README.md +4 -1
- data/lib/models/events/event.rb +4 -0
- data/lib/models/events/instance.rb +12 -2
- data/lib/models/seating/plan.rb +12 -0
- data/lib/models/tickets/band.rb +5 -0
- data/lib/models/tickets/price.rb +1 -1
- data/lib/models/tickets/price_list.rb +15 -5
- data/lib/spektrix.rb +9 -2
- data/lib/spektrix/base.rb +5 -0
- data/lib/spektrix/debug_middleware.rb +50 -0
- data/lib/spektrix/version.rb +1 -1
- data/spektrix.gemspec +0 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c78a69fb34e85fa562d264623827505560763571
|
4
|
+
data.tar.gz: c0c4fc02d52d08017a45281466e65b003b219657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
|
data/lib/models/events/event.rb
CHANGED
@@ -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
|
34
|
-
Tickets::PriceList.where(instance_id: self.id).first
|
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
|
data/lib/models/seating/plan.rb
CHANGED
@@ -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
|
data/lib/models/tickets/band.rb
CHANGED
data/lib/models/tickets/price.rb
CHANGED
@@ -5,16 +5,26 @@ module Spektrix
|
|
5
5
|
collection_path "price-lists"
|
6
6
|
|
7
7
|
after_find ->(r) do
|
8
|
-
bands
|
9
|
-
ticket_types
|
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
|
+
|
data/lib/spektrix.rb
CHANGED
@@ -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
|
|
data/lib/spektrix/base.rb
CHANGED
@@ -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
|
data/lib/spektrix/version.rb
CHANGED
data/spektrix.gemspec
CHANGED
@@ -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:
|
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
|