chiketto 1.0.1 → 1.1.0

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: 8cae275a1c252132bdf5816bd1461c612fcf2740
4
- data.tar.gz: 3b66fba0cf486366f2985360dc812b269273e2e6
3
+ metadata.gz: 4b827860000ff009a57e286076cd4beb25174d3c
4
+ data.tar.gz: c97bb7ae86c3102604d366e18eac425993dacf89
5
5
  SHA512:
6
- metadata.gz: 5138116f633dd6a66f6145185198e23c63075b63abc66809dbfd452e88bc2f77700f127ead49a21b6a8765ef40e96fe1bd8e1d9d565319334726464354edb1a3
7
- data.tar.gz: f2bb97b2eaf74af53c4f9537ec4ada42a00e882a4525e595ed9aab67984fc654b1758005d988714400ec7b2a9d6c27d233cf42dbc2e633e4d950c16b397a7200
6
+ metadata.gz: 535b022afc7dda335441249c3fffbe5a40558da0ba6c4ad41281aa7427fd4ae99198843dc6bab57301d172d702329cc4f436206f8c54adb69f4850f702aa0f72
7
+ data.tar.gz: 236706d3f4dc0dd3e652483aed44334d0393fc1da3be702f6b4c77ec82b4ed13706ed834b1a3311139171fcafeb3589caf27cb68522e032cb98385dde044bd41
@@ -1,8 +1,6 @@
1
1
  module Chiketto
2
2
  ENDPOINT = 'https://www.eventbriteapi.com/v3/'
3
3
 
4
- require 'hash_ext'
5
-
6
4
  require 'chiketto/exception'
7
5
  require 'chiketto/version'
8
6
  require 'chiketto/attribute'
@@ -1,8 +1,11 @@
1
1
  module Chiketto
2
2
  class Category < Resource
3
- attr_accessor :name,
4
- :resource_uri,
5
- :short_name
3
+ attr_accessor :name, :resource_uri, :short_name
4
+
5
+ def self.find(id)
6
+ response = get "categories/#{id}"
7
+ new response.to_h
8
+ end
6
9
 
7
10
  def self.list
8
11
  categories = get 'categories'
@@ -1,27 +1,17 @@
1
1
  module Chiketto
2
2
  class Event < Resource
3
- attr_reader :resource_uri,
4
- :url,
5
- :capacity,
6
- :status,
7
- :logo,
8
- :logo_url
9
-
10
- attr_attrib :description,
11
- :name
12
-
13
- attr_date :start,
14
- :end,
15
- :created,
16
- :changed
3
+ attr_reader :resource_uri, :url, :capacity, :status, :logo, :logo_url,
4
+ :organizer_id, :venue_id, :category_id, :subcategory_id
5
+ attr_attrib :description, :name
6
+ attr_date :start, :end, :created, :changed
17
7
 
18
8
  def self.create(params)
19
9
  response = Event.post 'events', params
20
10
  Event.new response
21
11
  end
22
12
 
23
- def self.find(id)
24
- event = get "events/#{id}"
13
+ def self.find(id, params = {})
14
+ event = get "events/#{id}", params
25
15
  Event.new event
26
16
  end
27
17
 
@@ -36,7 +26,7 @@ module Chiketto
36
26
  end
37
27
 
38
28
  def category
39
- Category.new @category.to_h
29
+ @category = find_or_fetch_category(@category, @category_id)
40
30
  end
41
31
 
42
32
  def listed?
@@ -49,14 +39,21 @@ module Chiketto
49
39
  end
50
40
 
51
41
  def organizer
52
- Organizer.new @organizer.to_h
42
+ if @organizer.is_a?(Organizer)
43
+ @organizer
44
+ elsif @organizer
45
+ @organizer = Organizer.new @organizer.to_h
46
+ elsif @organizer_id
47
+ @organizer = Organizer.find @organizer_id
48
+ end
53
49
  end
54
50
 
55
51
  def subcategory
56
- Category.new @subcategory.to_h
52
+ @subcategory = find_or_fetch_category(@subcategory, @subcategory_id)
57
53
  end
58
54
 
59
55
  def ticket_classes
56
+ return [] unless @ticket_classes
60
57
  @ticket_classes.map do |t_class|
61
58
  TicketClass.new t_class.to_h
62
59
  end
@@ -68,11 +65,27 @@ module Chiketto
68
65
  end
69
66
 
70
67
  def venue
71
- Venue.new @venue.to_h
68
+ if @venue.is_a?(Venue)
69
+ @venue
70
+ elsif @venue
71
+ @venue = Venue.new @venue.to_h
72
+ elsif @venue_id
73
+ @venue = Venue.find @venue_id
74
+ end
72
75
  end
73
76
 
74
77
  private
75
78
 
79
+ def find_or_fetch_category(category, category_id)
80
+ if category.is_a?(Category)
81
+ category
82
+ elsif category
83
+ Category.new category.to_h
84
+ elsif category_id
85
+ Category.find category_id
86
+ end
87
+ end
88
+
76
89
  def self.find_questions(id, params = {})
77
90
  get "events/#{id}/questions", params
78
91
  end
@@ -4,8 +4,13 @@ module Chiketto
4
4
 
5
5
  attr_attrib :description
6
6
 
7
+ def self.find(id)
8
+ response = get "organizers/#{id}"
9
+ Organizer.new response
10
+ end
11
+
7
12
  def self.create(params)
8
- response = Organizer.post 'organizers', params
13
+ response = post 'organizers', params
9
14
  Chiketto::Organizer.new response
10
15
  end
11
16
  end
@@ -15,13 +15,15 @@ module Chiketto
15
15
  end
16
16
 
17
17
  def self.get(uri, params = {})
18
- uri = endpoint(uri) + query(params)
18
+ uri = endpoint(uri) + build_query_string(params)
19
19
  resource = open uri
20
20
  JSON.parse resource.read
21
+ rescue OpenURI::HTTPError => e
22
+ raise e unless e.message =~ /^404/
21
23
  end
22
24
 
23
25
  def self.post(uri, params = {})
24
- uri = URI.parse endpoint(uri) + query(params)
26
+ uri = URI.parse endpoint(uri) + build_query_string(params)
25
27
  resource = open_post uri
26
28
  JSON.parse resource
27
29
  end
@@ -42,8 +44,30 @@ module Chiketto
42
44
  response.body
43
45
  end
44
46
 
45
- def self.query(params)
46
- params.to_params
47
+ def self.build_query_string(params)
48
+ query_params = ''
49
+ stack = []
50
+
51
+ params.each do |k, v|
52
+ if v.is_a?(Hash)
53
+ stack << [k, v]
54
+ else
55
+ query_params << "#{k}=#{CGI::escape(v)}&"
56
+ end
57
+ end
58
+
59
+ stack.each do |parent, hash|
60
+ hash.each do |k, v|
61
+ if v.is_a?(Hash)
62
+ stack << ["#{parent}[#{k}]", v]
63
+ else
64
+ query_params << "#{parent}[#{k}]=#{CGI::escape(v)}&"
65
+ end
66
+ end
67
+ end
68
+
69
+ query_params.chop!
70
+ "&#{query_params}"
47
71
  end
48
72
 
49
73
  def self.token
@@ -2,6 +2,11 @@ module Chiketto
2
2
  class Venue < Resource
3
3
  attr_accessor :name
4
4
 
5
+ def self.find(id)
6
+ response = get "venues/#{id}"
7
+ new response
8
+ end
9
+
5
10
  def address
6
11
  Chiketto::Address.new @address.to_h
7
12
  end
@@ -1,3 +1,3 @@
1
1
  module Chiketto
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -60,9 +60,11 @@ class EventTest < MiniTest::Test
60
60
  end
61
61
 
62
62
  def test_categories_are_objects
63
- find_event
64
- assert_kind_of Chiketto::Category, @event.category
65
- assert_kind_of Chiketto::Category, @event.subcategory
63
+ VCR.use_cassette 'event-categories' do
64
+ find_event
65
+ assert_kind_of Chiketto::Category, @event.category
66
+ assert_kind_of Chiketto::Category, @event.subcategory
67
+ end
66
68
  end
67
69
 
68
70
  def test_questions_are_objects
@@ -74,18 +76,24 @@ class EventTest < MiniTest::Test
74
76
  end
75
77
 
76
78
  def test_organizer_is_object
77
- find_event
78
- assert_kind_of Chiketto::Organizer, @event.organizer
79
+ VCR.use_cassette 'event-organizer' do
80
+ find_event
81
+ assert_kind_of Chiketto::Organizer, @event.organizer
82
+ end
79
83
  end
80
84
 
81
85
  def test_venue_is_object
82
- find_event
83
- assert_kind_of Chiketto::Venue, @event.venue
86
+ VCR.use_cassette 'event-venue' do
87
+ find_event
88
+ assert_kind_of Chiketto::Venue, @event.venue
89
+ end
84
90
  end
85
91
 
86
92
  def test_ticket_classes_is_object
87
- find_event
88
- assert_kind_of Chiketto::TicketClass, @event.ticket_classes.first
93
+ VCR.use_cassette 'event-ticket_classes' do
94
+ @event = Chiketto::Event.find TEST_ID, expand: 'ticket_classes'
95
+ assert_kind_of Chiketto::TicketClass, @event.ticket_classes.first
96
+ end
89
97
  end
90
98
 
91
99
  def test_date_attributes
@@ -23,7 +23,7 @@ class OrganizerTest < MiniTest::Test
23
23
 
24
24
  def test_creating_an_organizer
25
25
  VCR.use_cassette 'organizer-create' do
26
- name = ENV['CI'] ? Time.new.to_s : 'Test Name'
26
+ name = ENV['CI'] ? Time.new.to_s : 'Test Organizer Name'
27
27
  organizer = Chiketto::Organizer.create 'organizer.name' => name
28
28
  assert_kind_of Chiketto::Organizer, organizer
29
29
  assert_equal name, organizer.name
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chiketto
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Radford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dotenv
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: vcr
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Chiketto is a ruby gem for interacting with the Eventbrite V3 API
@@ -101,8 +101,8 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - .gitignore
105
- - .travis.yml
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
106
  - Gemfile
107
107
  - LICENSE.txt
108
108
  - README.md
@@ -126,7 +126,6 @@ files:
126
126
  - lib/chiketto/user.rb
127
127
  - lib/chiketto/venue.rb
128
128
  - lib/chiketto/version.rb
129
- - lib/hash_ext.rb
130
129
  - test/address_test.rb
131
130
  - test/attendee_profile_test.rb
132
131
  - test/attendee_test.rb
@@ -152,17 +151,17 @@ require_paths:
152
151
  - lib
153
152
  required_ruby_version: !ruby/object:Gem::Requirement
154
153
  requirements:
155
- - - '>='
154
+ - - ">="
156
155
  - !ruby/object:Gem::Version
157
156
  version: '2.0'
158
157
  required_rubygems_version: !ruby/object:Gem::Requirement
159
158
  requirements:
160
- - - '>='
159
+ - - ">="
161
160
  - !ruby/object:Gem::Version
162
161
  version: '0'
163
162
  requirements: []
164
163
  rubyforge_project:
165
- rubygems_version: 2.0.14
164
+ rubygems_version: 2.4.5
166
165
  signing_key:
167
166
  specification_version: 4
168
167
  summary: Chiketto is a ruby gem for interacting with the Eventbrite V3 API
@@ -182,3 +181,4 @@ test_files:
182
181
  - test/ticket_class_test.rb
183
182
  - test/user_test.rb
184
183
  - test/venue_test.rb
184
+ has_rdoc:
@@ -1,27 +0,0 @@
1
- class Hash
2
- def to_params
3
- params = ''
4
- stack = []
5
-
6
- each do |k, v|
7
- if v.is_a?(Hash)
8
- stack << [k, v]
9
- else
10
- params << "#{k}=#{CGI::escape(v)}&"
11
- end
12
- end
13
-
14
- stack.each do |parent, hash|
15
- hash.each do |k, v|
16
- if v.is_a?(Hash)
17
- stack << ["#{parent}[#{k}]", v]
18
- else
19
- params << "#{parent}[#{k}]=#{CGI::escape(v)}&"
20
- end
21
- end
22
- end
23
-
24
- params.chop!
25
- "&#{params}"
26
- end
27
- end