eventick_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/.gitmodules +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/eventick.gemspec +29 -0
- data/lib/eventick.rb +75 -0
- data/lib/eventick/attendee.rb +56 -0
- data/lib/eventick/auth.rb +32 -0
- data/lib/eventick/base.rb +43 -0
- data/lib/eventick/checkin.rb +42 -0
- data/lib/eventick/event.rb +47 -0
- data/lib/eventick/ticket.rb +9 -0
- data/lib/eventick/version.rb +3 -0
- data/test/eventick/attendee_test.rb +45 -0
- data/test/eventick/auth_test.rb +35 -0
- data/test/eventick/checkin_test.rb +28 -0
- data/test/eventick/event_test.rb +47 -0
- data/test/eventick/eventick_test.rb +12 -0
- data/test/eventick/ticket_test.rb +14 -0
- data/test/fixtures/attendee.json +11 -0
- data/test/fixtures/attendees.json +74 -0
- data/test/fixtures/auth.json +3 -0
- data/test/fixtures/checkin.json +12 -0
- data/test/fixtures/event.json +14 -0
- data/test/fixtures/events.json +59 -0
- data/test/test_helper.rb +87 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a141c013a1e57169601e5b1c607673dad2c2ff28
|
4
|
+
data.tar.gz: 686802ddf7944effa42e6d85e11cdea9af22b71d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6c30fce7832f64bec007d67c4cca637f5bbd129c40ad598ac02e25b79eb8ffe8cf48e0fe35b54490ab59c1f9d85e77d49b994db93d9703d63595e68ae335ee2
|
7
|
+
data.tar.gz: c252e4b3d99f5efff112c2b27734de7390a56ecb4c1dd1dadcda1d0a182c23c587dba7af91462ca7d3e73b584781d8c5b7a1579dc153f9146430210a0b09cf31
|
data/.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.rvmrc
|
19
|
+
|
20
|
+
# OS generated files #
|
21
|
+
######################
|
22
|
+
.DS_Store
|
23
|
+
.DS_Store?
|
24
|
+
ehthumbs.db
|
25
|
+
Icon?
|
26
|
+
Thumbs.db
|
27
|
+
.com.apple.*
|
28
|
+
|
29
|
+
# IDE generated files #
|
30
|
+
#######################
|
31
|
+
*.esproj
|
32
|
+
*.esproj?
|
33
|
+
.project
|
34
|
+
.project?
|
35
|
+
.loadpath
|
36
|
+
.settings?
|
37
|
+
.*.sw[a-z]
|
38
|
+
nb*
|
39
|
+
.classpath
|
40
|
+
.settings/
|
41
|
+
*.NavData
|
42
|
+
|
data/.gitmodules
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
eventick
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p195
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lukas Alexandre
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Eventick
|
2
|
+
|
3
|
+
Eventick is a simple API wrapper public Eventick API.
|
4
|
+
|
5
|
+
TODO: Write a gem description
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'eventick'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install eventick
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/eventick.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'eventick/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "eventick_api"
|
9
|
+
gem.version = Eventick::VERSION
|
10
|
+
gem.authors = ["Lukas Alexandre", "Thiago Diniz"]
|
11
|
+
gem.email = ["lukasalexandre@me.com", "thiago@eventick.com.br"]
|
12
|
+
gem.description = %q{Eventick is a simple API wrapper for Eventick's public API.}
|
13
|
+
gem.summary = %q{Eventick is a simple API wrapper for Eventick's public API.}
|
14
|
+
gem.homepage = ""
|
15
|
+
gem.license = 'MIT'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency 'json'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rake'
|
24
|
+
gem.add_development_dependency 'turn'
|
25
|
+
gem.add_development_dependency 'guard-minitest'
|
26
|
+
gem.add_development_dependency 'rb-fsevent'
|
27
|
+
gem.add_development_dependency 'minitest'
|
28
|
+
gem.add_development_dependency 'fakeweb'
|
29
|
+
end
|
data/lib/eventick.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'cgi'
|
4
|
+
require 'openssl'
|
5
|
+
|
6
|
+
require_relative './eventick/version'
|
7
|
+
require_relative './eventick/auth'
|
8
|
+
require_relative './eventick/event'
|
9
|
+
require_relative './eventick/attendee'
|
10
|
+
require_relative './eventick/ticket'
|
11
|
+
require_relative './eventick/checkin'
|
12
|
+
|
13
|
+
module Eventick
|
14
|
+
BASE_URL = 'www.eventick.com.br'
|
15
|
+
BASE_PATH = '/api/v1/'
|
16
|
+
|
17
|
+
def self.config(&block)
|
18
|
+
@auth = Eventick::Auth.new &block
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get(resource, params={})
|
22
|
+
path = api_path resource
|
23
|
+
path = with_params path, params
|
24
|
+
method = Net::HTTP::Get.new(path)
|
25
|
+
|
26
|
+
request(method)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.put(resource, params={})
|
30
|
+
path = api_path resource
|
31
|
+
method = Net::HTTP::Put.new(path)
|
32
|
+
method.set_form_data(params)
|
33
|
+
method.content_type = 'application/json' if params.is_a? String
|
34
|
+
|
35
|
+
request(method, params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.request(method, params={})
|
39
|
+
uri = URI("https://#{ BASE_URL }")
|
40
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
41
|
+
http.use_ssl = true
|
42
|
+
|
43
|
+
if auth && auth.authenticated?
|
44
|
+
method.basic_auth auth_token, ""
|
45
|
+
end
|
46
|
+
|
47
|
+
response = http.start do |http|
|
48
|
+
http.request method
|
49
|
+
end
|
50
|
+
|
51
|
+
return { } unless response.is_a? Net::HTTPSuccess
|
52
|
+
# return response.body unless block_given?
|
53
|
+
# yield JSON.parse(response.body)
|
54
|
+
JSON.parse(response.body) unless response.body.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.api_path(resource)
|
58
|
+
BASE_PATH + resource
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.auth_token
|
62
|
+
@auth.token if @auth
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.auth
|
66
|
+
@auth
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def self.with_params(url, params )
|
71
|
+
escape_pair = Proc.new {|k,v| CGI.escape(k.to_s)+'='+CGI.escape(v.to_s) }
|
72
|
+
to_query = "?" + params.map(&escape_pair).join("&") unless params.empty?
|
73
|
+
"#{ url }#{ to_query }"
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Eventick
|
2
|
+
class Attendee < Base
|
3
|
+
resource "events/:event_id/attendees/:id"
|
4
|
+
|
5
|
+
attr_accessor :id, :name
|
6
|
+
attr_accessor :code, :ticket_type, :checked_at, :event_id
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
args.each do |key, value|
|
10
|
+
self.public_send("#{key}=", value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# class methods
|
15
|
+
def self.all(event)
|
16
|
+
params = params(event)
|
17
|
+
attendees_response = Eventick.get path(params)
|
18
|
+
attendees = attendees_response['attendees'].map { |attendee_json| self.new attendee_json }
|
19
|
+
attendees.each { |a| a.event_id = params[:event_id] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_by_id(event, attendee_id)
|
23
|
+
data = params(event, attendee_id)
|
24
|
+
attendees_response = Eventick.get path(data)
|
25
|
+
params = attendees_response['attendees'].first
|
26
|
+
attendee = self.new params unless params.empty?
|
27
|
+
attendee.event_id = data[:event_id]
|
28
|
+
attendee
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_index
|
32
|
+
self.name
|
33
|
+
end
|
34
|
+
|
35
|
+
def checkin
|
36
|
+
Checkin.create self
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_param
|
40
|
+
{ event_id: self.event_id, code: self.code }
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json
|
44
|
+
"{ 'id': #{ self.id }, 'checked_at': '#{ self.checkin_at }' }"
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def self.params(event, attendee_id = nil)
|
49
|
+
event_id = event
|
50
|
+
event_id = event.id if event.is_a? Event
|
51
|
+
params = { :event_id => event_id }
|
52
|
+
params.merge!({ id: attendee_id }) if attendee_id
|
53
|
+
params
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Eventick
|
4
|
+
class Auth < Base
|
5
|
+
resource "tokens"
|
6
|
+
|
7
|
+
attr_accessor :email
|
8
|
+
attr_writer :password
|
9
|
+
|
10
|
+
def initialize(&block)
|
11
|
+
block.call self if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def token
|
15
|
+
@token ||= (get)['token']
|
16
|
+
end
|
17
|
+
|
18
|
+
def authenticated?
|
19
|
+
!!@token
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def get
|
24
|
+
@token = nil
|
25
|
+
path = Eventick.api_path self.class.path
|
26
|
+
method = Net::HTTP::Get.new(path)
|
27
|
+
method.basic_auth @email, @password
|
28
|
+
|
29
|
+
Eventick.request(method)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Eventick
|
2
|
+
class Base
|
3
|
+
def self.resource(res)
|
4
|
+
@resource = res
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.path(args={})
|
8
|
+
if @resource
|
9
|
+
path = translate(args)
|
10
|
+
"#{ path }.json"
|
11
|
+
else
|
12
|
+
warn "The #{ self.name } class has not defined any resource path."
|
13
|
+
raise
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.translate(args)
|
18
|
+
last_resource_rexp = /\/:(.\w+)$/
|
19
|
+
resource_keys = /(?<=:)(.\w+)/
|
20
|
+
|
21
|
+
one = @resource.gsub(last_resource_rexp).count == 0
|
22
|
+
|
23
|
+
if args.empty?
|
24
|
+
matched = @resource.gsub(last_resource_rexp, "")
|
25
|
+
else
|
26
|
+
s_args = Hash[args.map{ |k, v| [k.to_s, v] }]
|
27
|
+
matched = @resource.gsub(resource_keys, s_args)
|
28
|
+
matched.gsub!(/:/ , "")
|
29
|
+
matched.gsub!(/\/$/ , "")
|
30
|
+
end
|
31
|
+
|
32
|
+
remaining = matched.gsub(resource_keys).count
|
33
|
+
|
34
|
+
if remaining != 0
|
35
|
+
warn "Missing arguments for #{ self.name } class resource path: #{ matched }."
|
36
|
+
raise
|
37
|
+
end
|
38
|
+
|
39
|
+
matched
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Eventick
|
2
|
+
class Checkin < Base
|
3
|
+
resource 'events/:event_id/attendees/:code'
|
4
|
+
|
5
|
+
attr_accessor :attendee, :checkin_time
|
6
|
+
|
7
|
+
def initialize(args={})
|
8
|
+
self.attendee = args[:attendee]
|
9
|
+
self.checkin_time = Time.now
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(attendee)
|
13
|
+
(self.new :attendee => attendee).save
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all(event,attendees)
|
17
|
+
params = params(event)
|
18
|
+
checkin_time = Time.now
|
19
|
+
attendees.each{ |a| a.checkin_at = checkin_time }
|
20
|
+
atts = attendees.map{ |a| a.to_json }.join(",")
|
21
|
+
data = "{ 'attendees': [#{ atts }] }"
|
22
|
+
checkin_response = Eventick.put path(params), data
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def save
|
27
|
+
params = self.attendee.to_param
|
28
|
+
checkin_response = Eventick.put self.class.path(params), { checked_at: checkin_time}
|
29
|
+
self.attendee.checked_at = checkin_time
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def self.params(event, attendee_code = nil)
|
35
|
+
event_id = event
|
36
|
+
event_id = event.id if event.is_a? Event
|
37
|
+
params = { event_id: event_id, code: "check_all"}
|
38
|
+
params[:code] = attendee_code if attendee_code
|
39
|
+
params
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Eventick
|
4
|
+
class Event < Base
|
5
|
+
resource "events/:id"
|
6
|
+
|
7
|
+
attr_accessor :id, :start_at, :title, :tickets, :venue, :slug
|
8
|
+
attr_reader :attendees, :all
|
9
|
+
|
10
|
+
# constructors
|
11
|
+
def initialize(args={})
|
12
|
+
links = args.delete('links')
|
13
|
+
args.each do |key, value|
|
14
|
+
self.public_send("#{key}=", value)
|
15
|
+
end
|
16
|
+
|
17
|
+
self.tickets = links['tickets'].map { |o| Ticket.new(o) } if links
|
18
|
+
end
|
19
|
+
|
20
|
+
# class methods
|
21
|
+
def self.all
|
22
|
+
events_response = Eventick.get path
|
23
|
+
events_response['events'].map { |event_response| self.new event_response }
|
24
|
+
end
|
25
|
+
|
26
|
+
# class methods
|
27
|
+
def self.find_by_id(id)
|
28
|
+
events_response = Eventick.get path({ id: id })
|
29
|
+
params = events_response['events'].first
|
30
|
+
self.new params unless params.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
# instance methods
|
34
|
+
def attendees(reload = false)
|
35
|
+
if reload || @attendees.nil?
|
36
|
+
@attendees = Attendee.all self
|
37
|
+
end
|
38
|
+
|
39
|
+
@attendees
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def self.auth_token
|
44
|
+
{ :auth_token => Eventick.auth_token }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Eventick
|
4
|
+
describe Attendee do
|
5
|
+
let (:attendee) { Attendee.new }
|
6
|
+
|
7
|
+
describe 'checking method initialization' do
|
8
|
+
fields = [:id, :name, :search_index, :code, :ticket_type, :checked_at]
|
9
|
+
|
10
|
+
it 'checking instance variables' do
|
11
|
+
fields.each do |field|
|
12
|
+
attendee.must_respond_to field
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'retrieving attendees' do
|
18
|
+
let(:events) { { id: 24 }}
|
19
|
+
let(:attendees) { { event_id: 24 } }
|
20
|
+
let(:attendee) { { event_id: 24, id: 145 } }
|
21
|
+
|
22
|
+
before do
|
23
|
+
fake_get_url Event.path(events), find_event_response, auth_params
|
24
|
+
fake_get_url Attendee.path(attendees), attendees_response, auth_params
|
25
|
+
fake_get_url Attendee.path(attendee), find_attendee_response, auth_params
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'all from event' do
|
29
|
+
event = Event.find_by_id(events[:id])
|
30
|
+
event.attendees.size.must_equal 10
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'all' do
|
34
|
+
attendees = Attendee.all(events[:id])
|
35
|
+
attendees.size.must_equal 10
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'find one' do
|
39
|
+
event_id, attendee_id = attendee[:event_id], attendee[:id]
|
40
|
+
attendee = Attendee.find_by_id(event_id, attendee_id)
|
41
|
+
attendee.must_be_kind_of Attendee
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Eventick
|
4
|
+
describe Auth do
|
5
|
+
let (:auth) { Eventick.auth }
|
6
|
+
|
7
|
+
describe 'checking method initialization' do
|
8
|
+
it ('email') { auth.must_respond_to :email }
|
9
|
+
it ('password=') { auth.must_respond_to :password= }
|
10
|
+
it ('password') { auth.wont_respond_to :password }
|
11
|
+
it ('token') { auth.must_respond_to :token }
|
12
|
+
it ('token=') { auth.wont_respond_to :token= }
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'initializing the object' do
|
16
|
+
new_auth = Auth.new do |eventick|
|
17
|
+
eventick.email = 'testing@eventick.com.br'
|
18
|
+
eventick.password = '123456'
|
19
|
+
end
|
20
|
+
new_auth.email.must_equal 'testing@eventick.com.br'
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'getting the api token' do
|
24
|
+
it 'with valid credentials' do
|
25
|
+
puts auth_response
|
26
|
+
auth.token.must_equal auth_params[:user]
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'with invalid credentials' do
|
30
|
+
Eventick.config {}
|
31
|
+
auth.token.must_be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Eventick
|
4
|
+
describe Checkin do
|
5
|
+
let (:checkin) { Checkin.new }
|
6
|
+
|
7
|
+
describe 'checking method initialization' do
|
8
|
+
it ('checking instance variables') do
|
9
|
+
checkin.must_respond_to :attendee
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'checkin attendees' do
|
14
|
+
let(:attendee) { Attendee.find_by_id(24, 145 ) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
fake_get_url Attendee.path({ event_id: 24, id: 145 } ), find_attendee_response, auth_params
|
18
|
+
fake_put_url Checkin.path({ event_id: 24, code: "AD54E" } ), "{\"boo\": 1 }", auth_params
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'just one' do
|
22
|
+
checkin_obj = attendee.checkin
|
23
|
+
checkin_obj.must_equal true
|
24
|
+
attendee.checked_at.wont_be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Eventick
|
4
|
+
describe Event do
|
5
|
+
let (:fields) { [:id, :start_at, :title, :tickets, :venue, :slug] }
|
6
|
+
|
7
|
+
describe 'checking method initialization' do
|
8
|
+
let (:event) { Event.new }
|
9
|
+
|
10
|
+
it ('cheking instance variables') do
|
11
|
+
fields.each do |field|
|
12
|
+
event.must_respond_to field
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'retrieving events' do
|
18
|
+
before do
|
19
|
+
fake_get_url Event.path, events_response, auth_params
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'all' do
|
23
|
+
events = Event.all
|
24
|
+
events.size.must_equal 11
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'retrieving one event' do
|
29
|
+
let(:params) { { id: 24 }}
|
30
|
+
let(:event) { Event.find_by_id params[:id] }
|
31
|
+
|
32
|
+
before do
|
33
|
+
fake_get_url Event.path(params), find_event_response, auth_params
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should be an Event object' do
|
37
|
+
event.must_be_kind_of Event
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'checking for required fields' do
|
41
|
+
fields.each do |field|
|
42
|
+
event.public_send(field).wont_be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe Eventick do
|
4
|
+
describe 'checking method initialization' do
|
5
|
+
it ('config') { Eventick.must_respond_to :config }
|
6
|
+
it ('auth_token') { Eventick.must_respond_to :auth_token }
|
7
|
+
|
8
|
+
it 'should have a version' do
|
9
|
+
Eventick::VERSION.wont_be_nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe Eventick::Ticket do
|
4
|
+
let(:args) { { id: 30, name: "name" } }
|
5
|
+
let(:ticket) { Eventick::Ticket.new args }
|
6
|
+
|
7
|
+
describe 'initialization with argument' do
|
8
|
+
it "should assing the values" do
|
9
|
+
args.keys.each do |field|
|
10
|
+
ticket.send(field).must_equal args[field]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
{
|
2
|
+
"attendees": [
|
3
|
+
{
|
4
|
+
"id":143,
|
5
|
+
"name":"Adones Cunha",
|
6
|
+
"code":null,
|
7
|
+
"ticket_type":"Gratuito",
|
8
|
+
"checked_at":null
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"id":140,
|
12
|
+
"name":"Bruno Coelho",
|
13
|
+
"code":null,
|
14
|
+
"ticket_type":"Gratuito",
|
15
|
+
"checked_at":null
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"id":148,
|
19
|
+
"name":"Bruno Luigi",
|
20
|
+
"code":"w4KKO5MZ2Um9Igzz",
|
21
|
+
"ticket_type":"Gratuito",
|
22
|
+
"checked_at":null
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"id":145,
|
26
|
+
"name":"Cirdes Henrique",
|
27
|
+
"code":null,
|
28
|
+
"ticket_type":"Gratuito",
|
29
|
+
"checked_at":null
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"id":142,
|
33
|
+
"name":"Clélia",
|
34
|
+
"code":null,
|
35
|
+
"ticket_type":"Gratuito",
|
36
|
+
"checked_at":null
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"id":146,
|
40
|
+
"name":"Felipe Gabardo",
|
41
|
+
"code":null,
|
42
|
+
"ticket_type":"Gratuito",
|
43
|
+
"checked_at":null
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"id":144,
|
47
|
+
"name":"Guilherme Barreto",
|
48
|
+
"code":null,
|
49
|
+
"ticket_type":"Gratuito",
|
50
|
+
"checked_at":"2013-05-17T15:41:07-03:00"
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"id":141,
|
54
|
+
"name":"Klayton De Oliveira",
|
55
|
+
"code":null,
|
56
|
+
"ticket_type":"Gratuito",
|
57
|
+
"checked_at":null
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"id":139,
|
61
|
+
"name":"Lailson Bandeira",
|
62
|
+
"code":null,
|
63
|
+
"ticket_type":"Gratuito",
|
64
|
+
"checked_at":null
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"id":147,
|
68
|
+
"name":"Pedro Aranha",
|
69
|
+
"code":null,
|
70
|
+
"ticket_type":"Gratuito",
|
71
|
+
"checked_at":null
|
72
|
+
}
|
73
|
+
]
|
74
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
{
|
2
|
+
"events":[
|
3
|
+
{
|
4
|
+
"id":24,
|
5
|
+
"title":"Cervejada do Eventick",
|
6
|
+
"start_at":"2011-11-17T18:00:00-03:00"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"id":22,
|
10
|
+
"title":"Conversa de Negócios",
|
11
|
+
"start_at":"2011-11-10T09:00:00-03:00"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"id":17,
|
15
|
+
"title":"Empreededorismo e advocacia",
|
16
|
+
"start_at":"2011-10-27T14:50:00-03:00"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"id":26,
|
20
|
+
"title":"Encontro #14 FrevoOnRails",
|
21
|
+
"start_at":"2011-11-21T17:30:00-03:00"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"id":8,
|
25
|
+
"title":"exemplo de evento",
|
26
|
+
"start_at":"2013-12-01T18:00:00-03:00"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"id":547,
|
30
|
+
"title":"Manguezal Meetup",
|
31
|
+
"start_at":"2012-07-26T16:00:00-03:00"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"id":192,
|
35
|
+
"title":"Manguezal Meetup",
|
36
|
+
"start_at":"2012-03-02T16:30:00-03:00"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"id":2495,
|
40
|
+
"title":"Manguezal Meetup - Demo Edition",
|
41
|
+
"start_at":"2013-07-05T18:00:00-03:00"
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"id":11,
|
45
|
+
"title":"PE Nova Musica",
|
46
|
+
"start_at":"2011-10-11T23:00:00-03:00"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"id":1218,
|
50
|
+
"title":"Sunset Conecta.la: Edição especial do Maguez.al",
|
51
|
+
"start_at":"2012-12-27T18:00:00-03:00"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"id":108,
|
55
|
+
"title":"Testing",
|
56
|
+
"start_at":"2012-01-07T20:51:00-03:00"
|
57
|
+
}
|
58
|
+
]
|
59
|
+
}
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'turn'
|
4
|
+
require 'fakeweb'
|
5
|
+
require File.expand_path('../../lib/eventick.rb', __FILE__)
|
6
|
+
|
7
|
+
module TestHelpers
|
8
|
+
BASE_PATH = File.expand_path('../fixtures', __FILE__)
|
9
|
+
|
10
|
+
def fetch_fixture_path(path)
|
11
|
+
File.join(BASE_PATH, path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def auth_url(path, auth)
|
15
|
+
if !auth.empty? && auth[:user]
|
16
|
+
pass = ":#{ escape(auth[:password]) }" if auth[:password]
|
17
|
+
auth_str = "#{ escape(auth[:user]) }#{ pass }@"
|
18
|
+
end
|
19
|
+
|
20
|
+
"https://#{ auth_str }www.eventick.com.br/api/v1/#{ path }"
|
21
|
+
end
|
22
|
+
|
23
|
+
def fake_get_url(path, response, auth={}, params={})
|
24
|
+
url = compose_url path, auth, params
|
25
|
+
FakeWeb.register_uri(:get, url, :body => response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fake_put_url(path, response, auth={})
|
29
|
+
url = auth_url(path, auth)
|
30
|
+
FakeWeb.register_uri(:put, url, :body => response)
|
31
|
+
end
|
32
|
+
|
33
|
+
def with_params(url, params )
|
34
|
+
escape_pair = Proc.new { |k,v| escape(k) + '=' + escape(v) }
|
35
|
+
to_query = '?' + params.map(&escape_pair).join('&') unless params.empty?
|
36
|
+
"#{ url }#{ to_query }"
|
37
|
+
end
|
38
|
+
|
39
|
+
def escape(params)
|
40
|
+
CGI.escape params.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def compose_url(path, auth, params)
|
44
|
+
with_params auth_url(path, auth), params
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class MiniTest::Spec
|
49
|
+
include TestHelpers
|
50
|
+
let (:auth_params) { { :user => 'dpoi2154wijdsk4fo65ow4o2pkd' } }
|
51
|
+
|
52
|
+
let (:auth_response) { fetch_fixture_path('auth.json') }
|
53
|
+
let (:events_response) { fetch_fixture_path('events.json') }
|
54
|
+
let (:find_event_response) { fetch_fixture_path('event.json') }
|
55
|
+
let (:attendees_response) { fetch_fixture_path('attendees.json') }
|
56
|
+
let (:find_attendee_response) { fetch_fixture_path('attendee.json') }
|
57
|
+
let (:checkin_response) { fetch_fixture_path('checkin.json') }
|
58
|
+
|
59
|
+
before do
|
60
|
+
FakeWeb.allow_net_connect = false
|
61
|
+
|
62
|
+
register_malformed_token_request
|
63
|
+
register_token_request
|
64
|
+
|
65
|
+
Eventick.config do |eventick|
|
66
|
+
eventick.email = 'testing@eventick.com.br'
|
67
|
+
eventick.password = '12345678'
|
68
|
+
end
|
69
|
+
|
70
|
+
Eventick.auth_token
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def register_malformed_token_request
|
75
|
+
FakeWeb.register_uri(
|
76
|
+
:get,
|
77
|
+
'https://www.eventick.com.br/api/v1/tokens.json',
|
78
|
+
:body => 'The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.',
|
79
|
+
:status => ['401', 'Not Authorized']
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
def register_token_request
|
84
|
+
fake_get_url Eventick::Auth.path, auth_response, { :user => 'testing@eventick.com.br', :password => 12345678 }
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eventick_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lukas Alexandre
|
8
|
+
- Thiago Diniz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: turn
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: guard-minitest
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rb-fsevent
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: minitest
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: fakeweb
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: Eventick is a simple API wrapper for Eventick's public API.
|
113
|
+
email:
|
114
|
+
- lukasalexandre@me.com
|
115
|
+
- thiago@eventick.com.br
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- .gitmodules
|
122
|
+
- .ruby-gemset
|
123
|
+
- .ruby-version
|
124
|
+
- .travis.yml
|
125
|
+
- Gemfile
|
126
|
+
- Guardfile
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.md
|
129
|
+
- Rakefile
|
130
|
+
- eventick.gemspec
|
131
|
+
- lib/eventick.rb
|
132
|
+
- lib/eventick/attendee.rb
|
133
|
+
- lib/eventick/auth.rb
|
134
|
+
- lib/eventick/base.rb
|
135
|
+
- lib/eventick/checkin.rb
|
136
|
+
- lib/eventick/event.rb
|
137
|
+
- lib/eventick/ticket.rb
|
138
|
+
- lib/eventick/version.rb
|
139
|
+
- test/eventick/attendee_test.rb
|
140
|
+
- test/eventick/auth_test.rb
|
141
|
+
- test/eventick/checkin_test.rb
|
142
|
+
- test/eventick/event_test.rb
|
143
|
+
- test/eventick/eventick_test.rb
|
144
|
+
- test/eventick/ticket_test.rb
|
145
|
+
- test/fixtures/attendee.json
|
146
|
+
- test/fixtures/attendees.json
|
147
|
+
- test/fixtures/auth.json
|
148
|
+
- test/fixtures/checkin.json
|
149
|
+
- test/fixtures/event.json
|
150
|
+
- test/fixtures/events.json
|
151
|
+
- test/test_helper.rb
|
152
|
+
homepage: ''
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - '>='
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.0.5
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Eventick is a simple API wrapper for Eventick's public API.
|
176
|
+
test_files:
|
177
|
+
- test/eventick/attendee_test.rb
|
178
|
+
- test/eventick/auth_test.rb
|
179
|
+
- test/eventick/checkin_test.rb
|
180
|
+
- test/eventick/event_test.rb
|
181
|
+
- test/eventick/eventick_test.rb
|
182
|
+
- test/eventick/ticket_test.rb
|
183
|
+
- test/fixtures/attendee.json
|
184
|
+
- test/fixtures/attendees.json
|
185
|
+
- test/fixtures/auth.json
|
186
|
+
- test/fixtures/checkin.json
|
187
|
+
- test/fixtures/event.json
|
188
|
+
- test/fixtures/events.json
|
189
|
+
- test/test_helper.rb
|