centaman 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1887f7c0c2070ad38a77be8da73bfe2b69e7b173
4
+ data.tar.gz: 0cc3e7896724aa270dfb3bd6327622f6ea1a3d1d
5
+ SHA512:
6
+ metadata.gz: 1ba8f97dc262947e919695bf75aade6b4bf9dd473222ac3957f62fde6b066c89f2fb3c0027e71ad3958e957a09d280917cb416326e3b3f21c6199efe2d6c303c
7
+ data.tar.gz: cc3857bea3245a7eacbae62586ef5cb95b0885a592c11e1402b35f269ec58ba983774ab4e3cf0fe33658fe486c6df9749708b247d4cb0de43ea80db39fdc1b3f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ .DS_Store
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in centaman.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 dianacamacho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Centaman
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/centaman`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'centaman'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install centaman
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Required Environment Variables
28
+
29
+ This gem assumes the following environment variables are defined by the application
30
+
31
+ - CENTAMAN_API (Centaman API endpoint, ex: https://taxi.centaman.net/CentamanAPI)
32
+ - API_USERNAME (Centaman API username)
33
+ - API_PASSWORD (Centaman API password)
34
+ - FIXIE_URL (Optional. Used with FIXIE proxy to route outbound requests through a set of static IP addresses)
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/centaman.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "centaman"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/centaman.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'centaman/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "centaman"
8
+ spec.version = Centaman::VERSION
9
+ spec.authors = ["francirp", "dianacamacho"]
10
+ spec.email = ["ryan@launchpadlab.com", "dcam1901@gmail.com"]
11
+
12
+ spec.summary = "Wrapper for the Centaman Ticketing API"
13
+ spec.description = "Wrapper for the Centaman Ticketing API"
14
+ spec.homepage = "https://github.com/LaunchPadLab/centaman"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+
37
+ spec.add_dependency "httparty"
38
+ end
data/lib/centaman.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'centaman/version'
2
+ require 'centaman/wrapper'
3
+ require 'centaman/service'
4
+ require 'centaman/json_wrapper'
5
+ require 'centaman/object'
6
+ require 'centaman/filter'
7
+ require 'centaman/attribute'
8
+ require 'centaman/service/booking_time'
9
+ require 'centaman/service/booking_type'
10
+ require 'centaman/service/capacity'
11
+ require 'centaman/service/coupon_check'
12
+ require 'centaman/service/create_customer'
13
+ require 'centaman/service/extra'
14
+ require 'centaman/service/gift_ticket'
15
+ require 'centaman/service/purchase_ticket'
16
+ require 'centaman/service/ticket_type'
17
+ require 'centaman/object/booking_time'
18
+ require 'centaman/object/booking_type'
19
+ require 'centaman/object/capacity'
20
+ require 'centaman/object/coupon_check'
21
+ require 'centaman/object/customer'
22
+ require 'centaman/object/effect'
23
+ require 'centaman/object/extra'
24
+ require 'centaman/object/gift_ticket'
25
+ require 'centaman/object/purchased_ticket'
26
+ require 'centaman/object/ticket_type'
27
+ require 'httparty'
28
+
29
+ module Centaman
30
+ end
@@ -0,0 +1,63 @@
1
+ module Centaman
2
+ #:nodoc:
3
+ class Attribute
4
+ attr_reader :centaman_key, :app_key, :type
5
+ attr_accessor :value
6
+
7
+ def initialize(args = {})
8
+ @centaman_key = args[:centaman_key]
9
+ @app_key = args[:app_key]
10
+ @type = args.fetch(:type, :string)
11
+ end
12
+
13
+ def parse_value
14
+ parsed_value = send(type)
15
+ @value = parsed_value
16
+ end
17
+
18
+ def string
19
+ value
20
+ end
21
+
22
+ def float
23
+ value
24
+ end
25
+
26
+ def integer
27
+ value.try(:to_i)
28
+ end
29
+
30
+ def boolean
31
+ value
32
+ end
33
+
34
+ def datetime
35
+ DateTime.parse(value)
36
+ end
37
+
38
+ def centaman_description
39
+ value
40
+ end
41
+
42
+ def display_time
43
+ array = value.split(":")
44
+ hour = array[0].try(:to_i)
45
+ minute = array[1].try(:to_i)
46
+ period = hour >= 12 ? 'pm' : 'am'
47
+ hour = hour > 12 ? hour - 12 : hour
48
+ return "#{hour}#{period}" if minute == 0
49
+ "#{hour}:#{minute}#{period}"
50
+ # return [array.first, array[1]].join(":")
51
+ end
52
+
53
+ def age_group
54
+ return 'adult' if value.downcase.include?("adult")
55
+ return 'child' if value.downcase.include?("child")
56
+ return 'adult'
57
+ end
58
+
59
+ def display_age_group
60
+ age_group.capitalize
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,46 @@
1
+ module Centaman
2
+ #:nodoc:
3
+ class Filter
4
+ attr_reader :booking_type_id, :booking_time_id, :start_date, :end_date
5
+
6
+ def initialize(args = {})
7
+ @booking_type_id = args[:booking_type_id].try(:to_i)
8
+ @booking_time_id = args[:booking_time_id].try(:to_i)
9
+ @start_date = args[:start_date]
10
+ @end_date = args[:end_date]
11
+ end
12
+
13
+ def find_booking_type(booking_type_id)
14
+ booking_types.detect { |c| c.booking_type_id == booking_type_id }
15
+ end
16
+
17
+ def find_booking_time(booking_time_id)
18
+ raise "booking_time_id is required for find_booking_time method of #{self.class.name} class" if booking_time_id.nil?
19
+ booking_times.detect { |c| c.id.to_s == booking_time_id.to_s }
20
+ end
21
+
22
+ def booking_types
23
+ @booking_types ||= Centaman::Service::BookingType.new.objects
24
+ end
25
+
26
+ def tickets
27
+ @tickets ||= Centaman::Service::TicketType.new(booking_time_id: booking_time_id).objects
28
+ end
29
+
30
+ def booking_times
31
+ @booking_times ||= Centaman::Service::BookingTime.new(
32
+ booking_type_id: booking_type_id,
33
+ start_date: start_date,
34
+ end_date: end_date
35
+ ).objects
36
+ end
37
+
38
+ def gift_tickets
39
+ @gift_tickets ||= Centaman::Service::GiftTicket.new.objects
40
+ end
41
+
42
+ def capacity
43
+ @capacity ||= Centaman::Service::Capacity.new(booking_time_id: booking_time_id, start_date: start_date).objects.first
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ module Centaman
2
+ #:nodoc:
3
+ module JsonWrapper
4
+ def objects
5
+ @all ||= build_objects(self.fetch_all)
6
+ end
7
+
8
+ # i.e. from GET of an index
9
+ def build_objects(resp)
10
+ return [] unless resp.respond_to?(:map)
11
+ @tickets = resp.map do |ticket_hash|
12
+ object_class.new(ticket_hash.merge(additional_hash_to_serialize_after_response))
13
+ end
14
+ end
15
+
16
+ # i.e. from GET of a show or POST
17
+ def build_object(resp)
18
+ return resp unless resp.respond_to?(:merge)
19
+ @build_object ||= object_class.new(resp.merge(additional_hash_to_serialize_after_response))
20
+ end
21
+
22
+ def additional_hash_to_serialize_after_response
23
+ {}
24
+ end
25
+
26
+ def object_class
27
+ raise "object_class is required for #{self.class.name}"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ module Centaman
2
+ #:nodoc:
3
+ class Object
4
+ def initialize(args = {})
5
+ define_variables(args)
6
+ after_init(args)
7
+ end
8
+
9
+ def define_variables(args)
10
+ attributes.each do |attribute|
11
+ val = args[attribute.centaman_key]
12
+ attribute.value = val
13
+ attribute.parse_value
14
+ self.class.__send__(:attr_accessor, attribute.app_key)
15
+ instance_variable_set("@#{attribute.app_key}", attribute.value)
16
+ end
17
+ end
18
+
19
+ def attributes
20
+ [] # overwritten by subclasses
21
+ end
22
+
23
+ def after_init(args)
24
+ # hook for subclasses
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,122 @@
1
+ module Centaman
2
+ #:nodoc:
3
+ # rubocop:disable Metrics/ClassLength
4
+ class Object::BookingTime < Centaman::Object
5
+ attr_reader :sold_out
6
+
7
+ def define_variables(args)
8
+ super
9
+ @sold_out = vacancy <= 0 || is_booked_exclusively
10
+ end
11
+
12
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
13
+ def json
14
+ {
15
+ id: id,
16
+ booking_type_id: booking_type_id,
17
+ booking_type_description: booking_type_description,
18
+ description: description,
19
+ start_date: start_date.strftime('%Y-%m-%d'),
20
+ start_time: start_time,
21
+ end_time: end_time,
22
+ display_start_time: display_start_time,
23
+ display_end_time: display_end_time,
24
+ capacity: capacity,
25
+ vacancy: vacancy,
26
+ remaining: remaining,
27
+ booking_fee: booking_fee,
28
+ booking_fee_item_code: booking_fee_item_code,
29
+ cancelled: cancelled,
30
+ sold_out: sold_out
31
+ }
32
+ end
33
+ # rubocop:enable Metrics/MethodLength
34
+
35
+ # rubocop:disable Metrics/MethodLength
36
+ def attributes
37
+ [
38
+ Centaman::Attribute.new(
39
+ centaman_key: 'TimedTicketTypeId',
40
+ app_key: :id,
41
+ type: :integer
42
+ ),
43
+ Centaman::Attribute.new(
44
+ centaman_key: 'BookingTypeId',
45
+ app_key: :booking_type_id,
46
+ type: :integer
47
+ ),
48
+ Centaman::Attribute.new(
49
+ centaman_key: 'BookingTypeDescription',
50
+ app_key: :booking_type_description,
51
+ type: :string
52
+ ),
53
+ Centaman::Attribute.new(
54
+ centaman_key: 'TimedTicketTypeDescription',
55
+ app_key: :description,
56
+ type: :centaman_description
57
+ ),
58
+ Centaman::Attribute.new(
59
+ centaman_key: 'StartDate',
60
+ app_key: :start_date,
61
+ type: :datetime
62
+ ),
63
+ Centaman::Attribute.new(
64
+ centaman_key: 'StartTime',
65
+ app_key: :start_time,
66
+ type: :string
67
+ ),
68
+ Centaman::Attribute.new(
69
+ centaman_key: 'EndTime',
70
+ app_key: :end_time,
71
+ type: :string
72
+ ),
73
+ Centaman::Attribute.new(
74
+ centaman_key: 'StartTime',
75
+ app_key: :display_start_time,
76
+ type: :display_time
77
+ ),
78
+ Centaman::Attribute.new(
79
+ centaman_key: 'EndTime',
80
+ app_key: :display_end_time,
81
+ type: :display_time
82
+ ),
83
+ Centaman::Attribute.new(
84
+ centaman_key: 'Capacity',
85
+ app_key: :capacity,
86
+ type: :integer
87
+ ),
88
+ Centaman::Attribute.new(
89
+ centaman_key: 'vacancy',
90
+ app_key: :vacancy,
91
+ type: :integer
92
+ ),
93
+ Centaman::Attribute.new(
94
+ centaman_key: 'vacancy',
95
+ app_key: :remaining,
96
+ type: :integer
97
+ ),
98
+ Centaman::Attribute.new(
99
+ centaman_key: 'Bookingfee',
100
+ app_key: :booking_fee,
101
+ type: :float
102
+ ),
103
+ Centaman::Attribute.new(
104
+ centaman_key: 'BookingFeeItemCode',
105
+ app_key: :booking_fee_item_code,
106
+ type: :integer
107
+ ),
108
+ Centaman::Attribute.new(
109
+ centaman_key: 'Cancelled',
110
+ app_key: :cancelled,
111
+ type: :boolean
112
+ ),
113
+ Centaman::Attribute.new(
114
+ centaman_key: 'IsBookedExclusively',
115
+ app_key: :is_booked_exclusively,
116
+ type: :boolean
117
+ )
118
+ ]
119
+ end
120
+ # rubocop:enable Metrics/MethodLength
121
+ end
122
+ end