eventbrite-api 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +12 -0
  6. data/Gemfile +14 -0
  7. data/Gemfile.lock +86 -0
  8. data/LICENSE +22 -0
  9. data/README.md +2 -0
  10. data/Rakefile +51 -0
  11. data/VERSION +1 -0
  12. data/eventbrite-api.gemspec +86 -0
  13. data/lib/eventbrite-api.rb +15 -0
  14. data/lib/eventbrite/api/client.rb +59 -0
  15. data/lib/eventbrite/api/helper.rb +27 -0
  16. data/lib/eventbrite/api/model/base.rb +85 -0
  17. data/lib/eventbrite/api/model/event.rb +23 -0
  18. data/lib/eventbrite/api/model/event_ticket_class.rb +11 -0
  19. data/lib/eventbrite/api/model/order.rb +11 -0
  20. data/lib/eventbrite/api/model/organizer.rb +11 -0
  21. data/lib/eventbrite/api/model/owned_event.rb +11 -0
  22. data/lib/eventbrite/api/model/owned_event_attendee.rb +11 -0
  23. data/lib/eventbrite/api/model/owned_event_order.rb +11 -0
  24. data/lib/eventbrite/api/model/user.rb +11 -0
  25. data/lib/eventbrite/api/model/user_order.rb +11 -0
  26. data/lib/eventbrite/api/model/user_organizer.rb +11 -0
  27. data/lib/eventbrite/api/model/user_venue.rb +11 -0
  28. data/lib/eventbrite/api/model/venue.rb +11 -0
  29. data/spec/eventbrite/api/client_spec.rb +46 -0
  30. data/spec/eventbrite/api/model/base_spec.rb +11 -0
  31. data/spec/eventbrite/api/model/event_spec.rb +50 -0
  32. data/spec/eventbrite/api/model/owned_event_attendee_spec.rb +19 -0
  33. data/spec/eventbrite/api/model/owned_event_order_spec.rb +19 -0
  34. data/spec/eventbrite/api/model/owned_event_spec.rb +19 -0
  35. data/spec/fixtures/events/13270934723/publish.json +129 -0
  36. data/spec/fixtures/events/13270934723/unpublish.json +129 -0
  37. data/spec/fixtures/events_page1.json +2405 -0
  38. data/spec/fixtures/events_page2.json +2096 -0
  39. data/spec/fixtures/events_page3.json +1996 -0
  40. data/spec/fixtures/users/133925426255/owned_event_attendees.json +11 -0
  41. data/spec/fixtures/users/133925426255/owned_event_orders.json +327 -0
  42. data/spec/fixtures/users/133925426255/owned_events.json +181 -0
  43. data/spec/fixtures/users/me.json +13 -0
  44. data/spec/spec_helper.rb +98 -0
  45. metadata +116 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15ae47c9884854ba80aaa335707623ba72db8db1
4
+ data.tar.gz: d707620b6dd8bf643ab64bf230b4b494e7d67b8e
5
+ SHA512:
6
+ metadata.gz: 9d24e919a7050738b71cda412c40bc19fa3d8d152fff68b5b56cc18fe7a161a532ebf44653d610ac1add1160e26ad08804a72892c2b4dc9f1a5baec382468d7a
7
+ data.tar.gz: 55e06784e7b0f693096af22efc84eb52949fcd6ed219572bf7b0c024db15d4a2bc32346bec651bb2a3be8b1dc97999312c7e244465b757bc20a4c7176f4a4664
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.0@eventbrite-api
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+
3
+ language: ruby
4
+
5
+ cache: bundler
6
+
7
+ rvm:
8
+ - 2.2.0
9
+ - 2.1.3
10
+ - 2.0.0
11
+ - 1.9.3
12
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "oauth2"
4
+
5
+ group :development do
6
+ gem "jeweler"
7
+ end
8
+
9
+ group :test do
10
+ gem "rspec"
11
+ gem "webmock"
12
+ gem "timecop"
13
+ gem "simplecov", :require => false
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ crack (0.4.2)
7
+ safe_yaml (~> 1.0.0)
8
+ descendants_tracker (0.0.4)
9
+ thread_safe (~> 0.3, >= 0.3.1)
10
+ diff-lcs (1.2.5)
11
+ docile (1.1.5)
12
+ faraday (0.9.1)
13
+ multipart-post (>= 1.2, < 3)
14
+ git (1.2.9.1)
15
+ github_api (0.12.2)
16
+ addressable (~> 2.3)
17
+ descendants_tracker (~> 0.0.4)
18
+ faraday (~> 0.8, < 0.10)
19
+ hashie (>= 3.3)
20
+ multi_json (>= 1.7.5, < 2.0)
21
+ nokogiri (~> 1.6.3)
22
+ oauth2
23
+ hashie (3.3.2)
24
+ highline (1.6.21)
25
+ jeweler (2.0.1)
26
+ builder
27
+ bundler (>= 1.0)
28
+ git (>= 1.2.5)
29
+ github_api
30
+ highline (>= 1.6.15)
31
+ nokogiri (>= 1.5.10)
32
+ rake
33
+ rdoc
34
+ jwt (1.2.1)
35
+ mini_portile (0.6.2)
36
+ multi_json (1.10.1)
37
+ multi_xml (0.5.5)
38
+ multipart-post (2.0.0)
39
+ nokogiri (1.6.6.2)
40
+ mini_portile (~> 0.6.0)
41
+ nokogiri (1.6.6.2-java)
42
+ oauth2 (1.0.0)
43
+ faraday (>= 0.8, < 0.10)
44
+ jwt (~> 1.0)
45
+ multi_json (~> 1.3)
46
+ multi_xml (~> 0.5)
47
+ rack (~> 1.2)
48
+ rack (1.6.0)
49
+ rake (10.4.2)
50
+ rdoc (4.2.0)
51
+ rspec (3.1.0)
52
+ rspec-core (~> 3.1.0)
53
+ rspec-expectations (~> 3.1.0)
54
+ rspec-mocks (~> 3.1.0)
55
+ rspec-core (3.1.7)
56
+ rspec-support (~> 3.1.0)
57
+ rspec-expectations (3.1.2)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.1.0)
60
+ rspec-mocks (3.1.3)
61
+ rspec-support (~> 3.1.0)
62
+ rspec-support (3.1.2)
63
+ safe_yaml (1.0.4)
64
+ simplecov (0.9.1)
65
+ docile (~> 1.1.0)
66
+ multi_json (~> 1.0)
67
+ simplecov-html (~> 0.8.0)
68
+ simplecov-html (0.8.0)
69
+ thread_safe (0.3.4)
70
+ thread_safe (0.3.4-java)
71
+ timecop (0.7.1)
72
+ webmock (1.20.4)
73
+ addressable (>= 2.3.6)
74
+ crack (>= 0.3.2)
75
+
76
+ PLATFORMS
77
+ java
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ jeweler
82
+ oauth2
83
+ rspec
84
+ simplecov
85
+ timecop
86
+ webmock
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Maestrano
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ eventbrite-api
2
+ ===============
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "eventbrite-api"
18
+ gem.homepage = "http://github.com/BrunoChauvet/eventbrite-api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Integrate with Eventbrite API}
21
+ gem.description = %Q{Integrate with Eventbrite API}
22
+ gem.email = "it@maestrano.com"
23
+ gem.authors = ["BrunoChauvet"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "eventbrite-api #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,86 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: eventbrite-api 0.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "eventbrite-api"
9
+ s.version = "0.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["BrunoChauvet"]
14
+ s.date = "2015-02-24"
15
+ s.description = "Integrate with Eventbrite API"
16
+ s.email = "it@maestrano.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".ruby-version",
25
+ ".travis.yml",
26
+ "Gemfile",
27
+ "Gemfile.lock",
28
+ "LICENSE",
29
+ "README.md",
30
+ "Rakefile",
31
+ "VERSION",
32
+ "eventbrite-api.gemspec",
33
+ "lib/eventbrite-api.rb",
34
+ "lib/eventbrite/api/client.rb",
35
+ "lib/eventbrite/api/helper.rb",
36
+ "lib/eventbrite/api/model/base.rb",
37
+ "lib/eventbrite/api/model/event.rb",
38
+ "lib/eventbrite/api/model/event_ticket_class.rb",
39
+ "lib/eventbrite/api/model/order.rb",
40
+ "lib/eventbrite/api/model/organizer.rb",
41
+ "lib/eventbrite/api/model/owned_event.rb",
42
+ "lib/eventbrite/api/model/owned_event_attendee.rb",
43
+ "lib/eventbrite/api/model/owned_event_order.rb",
44
+ "lib/eventbrite/api/model/user.rb",
45
+ "lib/eventbrite/api/model/user_order.rb",
46
+ "lib/eventbrite/api/model/user_organizer.rb",
47
+ "lib/eventbrite/api/model/user_venue.rb",
48
+ "lib/eventbrite/api/model/venue.rb",
49
+ "spec/eventbrite/api/client_spec.rb",
50
+ "spec/eventbrite/api/model/base_spec.rb",
51
+ "spec/eventbrite/api/model/event_spec.rb",
52
+ "spec/eventbrite/api/model/owned_event_attendee_spec.rb",
53
+ "spec/eventbrite/api/model/owned_event_order_spec.rb",
54
+ "spec/eventbrite/api/model/owned_event_spec.rb",
55
+ "spec/fixtures/events/13270934723/publish.json",
56
+ "spec/fixtures/events/13270934723/unpublish.json",
57
+ "spec/fixtures/events_page1.json",
58
+ "spec/fixtures/events_page2.json",
59
+ "spec/fixtures/events_page3.json",
60
+ "spec/fixtures/users/133925426255/owned_event_attendees.json",
61
+ "spec/fixtures/users/133925426255/owned_event_orders.json",
62
+ "spec/fixtures/users/133925426255/owned_events.json",
63
+ "spec/fixtures/users/me.json",
64
+ "spec/spec_helper.rb"
65
+ ]
66
+ s.homepage = "http://github.com/BrunoChauvet/eventbrite-api"
67
+ s.licenses = ["MIT"]
68
+ s.rubygems_version = "2.4.5"
69
+ s.summary = "Integrate with Eventbrite API"
70
+
71
+ if s.respond_to? :specification_version then
72
+ s.specification_version = 4
73
+
74
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
75
+ s.add_runtime_dependency(%q<oauth2>, [">= 0"])
76
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
77
+ else
78
+ s.add_dependency(%q<oauth2>, [">= 0"])
79
+ s.add_dependency(%q<jeweler>, [">= 0"])
80
+ end
81
+ else
82
+ s.add_dependency(%q<oauth2>, [">= 0"])
83
+ s.add_dependency(%q<jeweler>, [">= 0"])
84
+ end
85
+ end
86
+
@@ -0,0 +1,15 @@
1
+ require 'eventbrite/api/helper.rb'
2
+ require 'eventbrite/api/client.rb'
3
+ require 'eventbrite/api/model/base.rb'
4
+ require 'eventbrite/api/model/user.rb'
5
+ require 'eventbrite/api/model/venue.rb'
6
+ require 'eventbrite/api/model/organizer.rb'
7
+ require 'eventbrite/api/model/event.rb'
8
+ require 'eventbrite/api/model/event_ticket_class.rb'
9
+ require 'eventbrite/api/model/order.rb'
10
+ require 'eventbrite/api/model/user_order.rb'
11
+ require 'eventbrite/api/model/user_venue.rb'
12
+ require 'eventbrite/api/model/user_organizer.rb'
13
+ require 'eventbrite/api/model/owned_event.rb'
14
+ require 'eventbrite/api/model/owned_event_attendee.rb'
15
+ require 'eventbrite/api/model/owned_event_order.rb'
@@ -0,0 +1,59 @@
1
+ require 'base64'
2
+ require 'oauth2'
3
+
4
+ module Eventbrite
5
+ module Api
6
+ class Client
7
+ include Eventbrite::Api::Helpers
8
+
9
+ attr_reader :client, :access_token
10
+
11
+ def initialize(options)
12
+ model :User
13
+ model :Venue
14
+ model :Organizer
15
+ model :Order
16
+ model :Event
17
+ model :EventTicketClass
18
+ model :UserOrder
19
+ model :UserVenue
20
+ model :UserOrganizer
21
+ model :OwnedEvent
22
+ model :OwnedEventAttendee
23
+ model :OwnedEventOrder
24
+
25
+ @redirect_uri = options[:redirect_uri]
26
+ @consumer = options[:consumer]
27
+ @access_token = options[:access_token]
28
+
29
+ @client = OAuth2::Client.new(@consumer[:key], @consumer[:secret], {
30
+ :site => 'https://www.eventbrite.com',
31
+ :authorize_url => '/oauth/authorize',
32
+ :token_url => '/oauth/token',
33
+ })
34
+ end
35
+
36
+ def get_access_code_url(params = {})
37
+ @client.auth_code.authorize_url(params.merge(redirect_uri: @redirect_uri))
38
+ end
39
+
40
+ def get_access_token(access_code)
41
+ @token = @client.auth_code.get_token(access_code, redirect_uri: @redirect_uri)
42
+ @access_token = @token.token
43
+ @token
44
+ end
45
+
46
+ def headers
47
+ {
48
+ 'Accept' => 'application/json',
49
+ 'Content-Type' => 'application/json'
50
+ }
51
+ end
52
+
53
+ def connection
54
+ @auth_connection ||= OAuth2::AccessToken.new(@client, @access_token)
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ class String
2
+ def underscore
3
+ self.gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
+ tr("-", "_").
7
+ downcase
8
+ end
9
+ end
10
+
11
+ module Eventbrite
12
+ module Api
13
+ module Helpers
14
+ def model(model_name)
15
+ method_name = model_name.to_s.underscore
16
+ variable_name = "@#{method_name}_model".to_sym
17
+ unless instance_variable_defined?(variable_name)
18
+ instance_variable_set(variable_name, Eventbrite::Api::Model.const_get("#{model_name}".to_sym).new(self, model_name.to_s))
19
+ self.define_singleton_method(method_name.to_sym) do
20
+ instance_variable_get(variable_name)
21
+ end
22
+ end
23
+ instance_variable_get(variable_name)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,85 @@
1
+ module Eventbrite
2
+ module Api
3
+ module Model
4
+ class Base
5
+
6
+ def initialize(client, model_name=nil)
7
+ @client = client
8
+ @model_name = model_name || 'Base'
9
+
10
+ @pagination = nil
11
+ @endpoint = nil
12
+ end
13
+
14
+ def model_route
15
+ @model_name.to_s.downcase
16
+ end
17
+
18
+ def get(opts={}, endpoint=nil)
19
+ @endpoint = endpoint
20
+ perform_request(url(opts, endpoint))
21
+ end
22
+
23
+ def find(id)
24
+ self.get(opts, id)
25
+ end
26
+
27
+ def create(object, opts={})
28
+ @client.connection.post(url(opts), {:headers => @client.headers, :body => object.to_json})
29
+ end
30
+
31
+ def update(id, object, opts={})
32
+ @client.connection.post(url(opts, id), {:headers => @client.headers, :body => object.to_json})
33
+ end
34
+
35
+ def all(opts)
36
+ all_pages = get(opts)
37
+ while @pagination && @pagination['page_number'] < @pagination['page_count']
38
+ all_pages.deep_merge!(next_page(opts))
39
+ end
40
+ all_pages
41
+ end
42
+
43
+ def next_page(opts={})
44
+ opts['params'] = [{'page'=>@pagination['page_number']+1}]
45
+ get(opts, @endpoint)
46
+ end
47
+
48
+ def previous_page(opts={})
49
+ opts['params'] = [{'page'=>@pagination['page_number']-1}]
50
+ get(opts, @endpoint)
51
+ end
52
+
53
+ protected
54
+ def url(opts={}, endpoint=nil)
55
+ if model_route == ''
56
+ target = "https://www.eventbriteapi.com/v3"
57
+ elsif endpoint
58
+ target = "#{resource_url(opts)}/#{endpoint}"
59
+ else
60
+ target = resource_url(opts)
61
+ end
62
+
63
+ if opts[:params]
64
+ params = opts[:params].map { |k,v| "#{k}=#{v}" }.join('&')
65
+ target = "#{target}?#{params}"
66
+ end
67
+ target
68
+ end
69
+
70
+ def resource_url(opts={})
71
+ target = "https://www.eventbriteapi.com/v3/#{model_route}"
72
+ opts.each { |k,v| target.gsub!(":#{k}", v) if v.is_a?(String) } unless opts.empty?
73
+ target
74
+ end
75
+
76
+ def perform_request(target)
77
+ response = @client.connection.get(target, {:headers => @client.headers})
78
+ hash = JSON.parse(response.body)
79
+ @pagination = hash['pagination']
80
+ hash
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end