chiketto 0.0.3 → 0.0.4

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: 83ec9115edcc91aebbee0a99c61dd44102464667
4
- data.tar.gz: d03b93c1ec3577ee45bfd8b488ca8f36f8f4e818
3
+ metadata.gz: dda2ccb3f3bb08a0fa9608d64fe991a454699238
4
+ data.tar.gz: 96bf882e5d1422ccb2302c3265cea13824d559d4
5
5
  SHA512:
6
- metadata.gz: 96505a6e856b26128f29a1c12f689432bf8d6ac6f5a57b3e5f757fccb9f8d2ec622a4e14d2212234df60f8d54a1daaf74c7676586112dcc5eed431bd32cc966e
7
- data.tar.gz: f33d909107e2710cec5b997baa7ad9a55169577fe1ad718ec2a649a2c99a973dc7126864856f251abded08226ec46891571417d8ff6b95b1cc7656e3119ff586
6
+ metadata.gz: 04304e643ed8c6fc72275d6255cddcb34c09821cea74df11baa73921c38037d8d3d2e5cb07f81556c8199c113331aa4eeba341c9d2cd310aa5e64f41691e70f6
7
+ data.tar.gz: 81958275e5cbfe1e511d22e098dd080e9bb84d3fffe85c84a8324cd2197473b2ffc63e11c3cc70e3bcb6278e26015cc2099ade2ecf3dcc11df17a2306eaab9a3
data/lib/chiketto.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  module Chiketto
2
2
  ENDPOINT = 'https://www.eventbriteapi.com/v3/'
3
3
 
4
+ require 'hash_ext'
5
+
4
6
  require 'chiketto/version'
5
7
  require 'chiketto/attribute'
6
8
  require 'chiketto/attr_attribute'
7
9
  require 'chiketto/resource'
8
10
  require 'chiketto/address'
11
+ require 'chiketto/category'
9
12
  require 'chiketto/event'
10
13
  require 'chiketto/organizer'
11
14
  require 'chiketto/ticket_class'
@@ -0,0 +1,12 @@
1
+ module Chiketto
2
+ class Category < Resource
3
+ attr_accessor :name,
4
+ :resource_uri,
5
+ :short_name
6
+
7
+ def self.list
8
+ categories = get 'categories'
9
+ categories['categories'].map { |cat| Chiketto::Category.new cat }
10
+ end
11
+ end
12
+ end
@@ -32,5 +32,10 @@ module Chiketto
32
32
  event = get "events/#{id}"
33
33
  Event.new event
34
34
  end
35
+
36
+ def self.search(params = {})
37
+ events = get 'events/search', params
38
+ events['events'].map { |event| Event.new event }
39
+ end
35
40
  end
36
41
  end
@@ -13,8 +13,8 @@ module Chiketto
13
13
  end
14
14
  end
15
15
 
16
- def self.get(uri)
17
- uri = endpoint uri
16
+ def self.get(uri, params = {})
17
+ uri = endpoint(uri) + query(params)
18
18
  resource = open uri
19
19
  JSON.parse resource.read
20
20
  end
@@ -23,6 +23,10 @@ module Chiketto
23
23
  ENDPOINT + uri + token
24
24
  end
25
25
 
26
+ def self.query(params)
27
+ params.to_params
28
+ end
29
+
26
30
  def self.token
27
31
  "?token=#{ENV['EVENTBRITE_API_TOKEN']}"
28
32
  end
@@ -1,3 +1,3 @@
1
1
  module Chiketto
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/hash_ext.rb ADDED
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class CategoryTest < MiniTest::Test
4
+ def list_categories
5
+ VCR.use_cassette 'catgories' do
6
+ @categories = Chiketto::Category.list
7
+ end
8
+ end
9
+
10
+ def test_categories_returns_list
11
+ list_categories
12
+ assert_kind_of Array, @categories
13
+ assert_kind_of Chiketto::Category, @categories.first
14
+ end
15
+
16
+ def test_category_responds_to_methods
17
+ list_categories
18
+ @category = @categories.first
19
+ assert_respond_to @category, :id
20
+ assert_respond_to @category, :name
21
+ assert_respond_to @category, :resource_uri
22
+ assert_respond_to @category, :short_name
23
+ end
24
+ end
data/test/event_test.rb CHANGED
@@ -3,18 +3,26 @@ require 'test_helper'
3
3
  class EventTest < MiniTest::Test
4
4
  TEST_ID = '9203575141'
5
5
 
6
- def setup
7
- VCR.use_cassette 'eventbriteapi' do
6
+ def find_event
7
+ VCR.use_cassette 'event-find' do
8
8
  @event = Chiketto::Event.find TEST_ID
9
9
  end
10
10
  end
11
11
 
12
+ def search_events
13
+ VCR.use_cassette 'event-search' do
14
+ @events = Chiketto::Event.search q: 'Test Event'
15
+ end
16
+ end
17
+
12
18
  def test_fetching_event
19
+ find_event
13
20
  assert_kind_of Chiketto::Event, @event
14
21
  assert_equal @event.id, TEST_ID
15
22
  end
16
23
 
17
24
  def test_event_exposes_data
25
+ find_event
18
26
  assert_respond_to @event, :id
19
27
  assert_respond_to @event, :name
20
28
  assert_respond_to @event, :description
@@ -33,31 +41,43 @@ class EventTest < MiniTest::Test
33
41
  end
34
42
 
35
43
  def test_name_attribute_is_valid
44
+ find_event
36
45
  assert_respond_to @event.name, :html
37
46
  assert_respond_to @event.name, :text
38
47
  end
39
48
 
40
49
  def test_description_attribute_is_valid
50
+ find_event
41
51
  assert_respond_to @event.description, :html
42
52
  assert_respond_to @event.description, :text
43
53
  end
44
54
 
45
55
  def test_organizer_is_object
56
+ find_event
46
57
  assert_kind_of Chiketto::Organizer, @event.organizer
47
58
  end
48
59
 
49
60
  def test_venue_is_object
61
+ find_event
50
62
  assert_kind_of Chiketto::Venue, @event.venue
51
63
  end
52
64
 
53
65
  def test_ticket_classes_is_object
66
+ find_event
54
67
  assert_kind_of Chiketto::TicketClass, @event.ticket_classes.first
55
68
  end
56
69
 
57
70
  def test_date_attributes
71
+ find_event
58
72
  assert_kind_of DateTime, @event.end
59
73
  assert_kind_of DateTime, @event.start
60
74
  assert_kind_of DateTime, @event.created
61
75
  assert_kind_of DateTime, @event.changed
62
76
  end
77
+
78
+ def test_search_returns_array_of_events
79
+ search_events
80
+ assert_kind_of Array, @events
81
+ assert_kind_of Chiketto::Event, @events.first
82
+ end
63
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chiketto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Radford
@@ -140,14 +140,17 @@ files:
140
140
  - lib/chiketto/address.rb
141
141
  - lib/chiketto/attr_attribute.rb
142
142
  - lib/chiketto/attribute.rb
143
+ - lib/chiketto/category.rb
143
144
  - lib/chiketto/event.rb
144
145
  - lib/chiketto/organizer.rb
145
146
  - lib/chiketto/resource.rb
146
147
  - lib/chiketto/ticket_class.rb
147
148
  - lib/chiketto/venue.rb
148
149
  - lib/chiketto/version.rb
150
+ - lib/hash_ext.rb
149
151
  - test/address_test.rb
150
152
  - test/attribute_test.rb
153
+ - test/category_test.rb
151
154
  - test/chiketto_test.rb
152
155
  - test/event_test.rb
153
156
  - test/organizer_test.rb
@@ -181,6 +184,7 @@ summary: Chiketto is a ruby gem for interacting with the Eventbrite V3 API
181
184
  test_files:
182
185
  - test/address_test.rb
183
186
  - test/attribute_test.rb
187
+ - test/category_test.rb
184
188
  - test/chiketto_test.rb
185
189
  - test/event_test.rb
186
190
  - test/organizer_test.rb