chiketto 0.0.12 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -7
- data/chiketto.gemspec +1 -1
- data/lib/chiketto.rb +1 -0
- data/lib/chiketto/event.rb +21 -4
- data/lib/chiketto/resource.rb +20 -1
- data/lib/chiketto/version.rb +1 -1
- data/test/event_test.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 960921d41a890c65c8139789bfbcace08a8386c8
|
4
|
+
data.tar.gz: a24198885b40f89733bd48004f6da18bf4915dc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99f3ecbcd868359bc5979f5fa486c78d6fa2bae91aa36e173bef085125e470b0f791b7789ade17a1827326c782462589cfee048d9c1a91627b87e78c0e61fd8e
|
7
|
+
data.tar.gz: 3b5752ea27d7593489e67b6cbd19d18100242dcc17165af70218664d284644e94679c68b246d662102ad0206095f18001a5846e35cd2ccfeaac6028c3cfc6864
|
data/README.md
CHANGED
@@ -5,7 +5,9 @@
|
|
5
5
|
|
6
6
|
Chiketto is a ruby gem for interacting with the Eventbrite V3 API, chiketto in Japanese literally means 'Ticket' and seems like a reasonable name given most of the obvious options are already taken. Chiketto works with Ruby 2.0 and above, since this is a new gem it makes little sense to support older, unsupported version of Ruby.
|
7
7
|
|
8
|
-
|
8
|
+
Chiketto falls back to the V1 API when dealing with updating and creating events, those these are the only instances. It's also worth noting that when using the V1 API Chiketto will make a second call to the V3 API in order to fetch the data. This is due to changes in the way data is formatted and what data is returned between the two API versions.
|
9
|
+
|
10
|
+
**This Gem is still very much a work in progress though may now be suitable for production use - version 1.0 should be ready late summer 2014**
|
9
11
|
|
10
12
|
## Installation
|
11
13
|
|
@@ -29,18 +31,29 @@ $ gem install chiketto
|
|
29
31
|
|
30
32
|
## Usage
|
31
33
|
|
32
|
-
Chiketto will read your API access token from the `EVENTBRITE_API_TOKEN`
|
34
|
+
Chiketto will read your API access token from the `EVENTBRITE_API_TOKEN` environment variable, you can also set it explicitly:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Chiketto.api_key = 'YOUR_API_KEY'
|
38
|
+
```
|
33
39
|
|
34
|
-
Chiketto allows you to
|
40
|
+
Chiketto allows you to access data from the Eventbrite API and formats it as Ruby objects for use within your application.
|
35
41
|
|
36
42
|
For example, once you've found an event on the API, Chiketto provides a simple interface for the various pieces of data to make working with it easier.
|
37
43
|
|
38
44
|
```ruby
|
39
45
|
event = Chiketto::Event.find 123456
|
40
|
-
event.name
|
41
|
-
event.name.html
|
42
|
-
event.organizer
|
43
|
-
event.organizer.name
|
46
|
+
event.name # => 'Event Name'
|
47
|
+
event.name.html # => '<p>Event Name</p>'
|
48
|
+
event.organizer # => Chicketto::Organizer
|
49
|
+
event.organizer.name # => 'Organizer Name'
|
50
|
+
```
|
51
|
+
|
52
|
+
You can also create new events, or update existing events (using the V1 API) and Chiketto will then return the updated / new event pulled from the V3 API.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
event.update name: 'Name'
|
56
|
+
Chiketto::Event.create name: 'Name', start_date: …, end_date: …
|
44
57
|
```
|
45
58
|
|
46
59
|
You can also use the search endpoint on the API to look up events and have an Array of events returned:
|
data/chiketto.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>=
|
21
|
+
spec.required_ruby_version = '>= 2.0'
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
24
|
spec.add_development_dependency "dotenv"
|
data/lib/chiketto.rb
CHANGED
data/lib/chiketto/event.rb
CHANGED
@@ -14,6 +14,14 @@ module Chiketto
|
|
14
14
|
:created,
|
15
15
|
:changed
|
16
16
|
|
17
|
+
def self.create(params)
|
18
|
+
params[:title] = params.delete(:name) if params[:name]
|
19
|
+
response = Event.post 'event_new', params
|
20
|
+
if response.fetch('process', false)
|
21
|
+
Event.find response['process']['id']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
def self.find(id)
|
18
26
|
event = get "events/#{id}"
|
19
27
|
Event.new event
|
@@ -25,22 +33,31 @@ module Chiketto
|
|
25
33
|
end
|
26
34
|
|
27
35
|
def attendees(params = {})
|
28
|
-
attendees =
|
36
|
+
attendees = Event.find_attendees @id, params
|
29
37
|
attendees['attendees'].map { |att| Attendee.new att }
|
30
38
|
end
|
31
39
|
|
32
40
|
def organizer
|
33
|
-
|
41
|
+
Organizer.new @organizer.to_h
|
34
42
|
end
|
35
43
|
|
36
44
|
def ticket_classes
|
37
45
|
@ticket_classes.map do |t_class|
|
38
|
-
|
46
|
+
TicketClass.new t_class.to_h
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def update(params)
|
51
|
+
params[:id] = @id
|
52
|
+
params[:title] = params.delete(:name) if params[:name]
|
53
|
+
response = Event.post 'event_update', params
|
54
|
+
if response.fetch('process', false)
|
55
|
+
response['process']['status'].upcase == 'OK'
|
39
56
|
end
|
40
57
|
end
|
41
58
|
|
42
59
|
def venue
|
43
|
-
|
60
|
+
Venue.new @venue.to_h
|
44
61
|
end
|
45
62
|
|
46
63
|
private
|
data/lib/chiketto/resource.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'open-uri'
|
3
|
+
require 'net/http'
|
3
4
|
|
4
5
|
module Chiketto
|
5
6
|
class Resource
|
@@ -19,16 +20,34 @@ module Chiketto
|
|
19
20
|
JSON.parse resource.read
|
20
21
|
end
|
21
22
|
|
23
|
+
def self.post(uri, params = {})
|
24
|
+
uri = URI.parse legacy_endpoint(uri) + query(params)
|
25
|
+
resource = open_post uri
|
26
|
+
JSON.parse resource
|
27
|
+
end
|
28
|
+
|
22
29
|
def self.endpoint(uri)
|
23
30
|
ENDPOINT + uri + token
|
24
31
|
end
|
25
32
|
|
33
|
+
def self.legacy_endpoint(uri)
|
34
|
+
LEGACY_ENDPOINT + uri + "?"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.open_post(uri)
|
38
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
39
|
+
http.use_ssl = true
|
40
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
41
|
+
request.add_field 'Authorization', "Bearer #{Chiketto.api_key}"
|
42
|
+
http.request(request).body
|
43
|
+
end
|
44
|
+
|
26
45
|
def self.query(params)
|
27
46
|
params.to_params
|
28
47
|
end
|
29
48
|
|
30
49
|
def self.token
|
31
|
-
"
|
50
|
+
"/?token=#{Chiketto.api_key}"
|
32
51
|
end
|
33
52
|
end
|
34
53
|
end
|
data/lib/chiketto/version.rb
CHANGED
data/test/event_test.rb
CHANGED
@@ -98,4 +98,38 @@ class EventTest < MiniTest::Test
|
|
98
98
|
end
|
99
99
|
assert_kind_of Array, @attendees
|
100
100
|
end
|
101
|
+
|
102
|
+
def test_updates_event_with_params
|
103
|
+
VCR.use_cassette 'event-update' do
|
104
|
+
find_event
|
105
|
+
response = @event.update name: 'Movember 2014'
|
106
|
+
assert response, 'Should return true after updating'
|
107
|
+
@event = Chiketto::Event.find @event.id
|
108
|
+
assert_equal 'Movember 2014', @event.name.to_s
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_update_returns_false_for_invalid_id
|
113
|
+
VCR.use_cassette 'event-update-fail' do
|
114
|
+
event = Chiketto::Event.new id: '12345'
|
115
|
+
response = event.update name: 'Movember 2014'
|
116
|
+
refute response, 'Should return false for invalid id'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_create_a_new_event
|
121
|
+
VCR.use_cassette 'event-create' do
|
122
|
+
event = Chiketto::Event.create name: 'Test Event Creation',
|
123
|
+
start_date: '2037-12-31 22:59:59', end_date: '2037-12-31 23:59:59'
|
124
|
+
assert_kind_of Chiketto::Event, event
|
125
|
+
assert_equal 'Test Event Creation', event.name.to_s
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_create_an_event_returns_false_on_failure
|
130
|
+
VCR.use_cassette 'event-create-failure' do
|
131
|
+
event = Chiketto::Event.create name: 'Test Event'
|
132
|
+
refute event, 'Should return false when API rejects creation'
|
133
|
+
end
|
134
|
+
end
|
101
135
|
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
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Radford
|
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
147
|
requirements:
|
148
148
|
- - ">="
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: '2.0'
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
153
|
- - ">="
|