diff --git a/.document b/.document new file mode 100644 index 0000000..ecf3673 --- /dev/null +++ b/.document @@ -0,0 +1,5 @@ +README.rdoc +lib/**/*.rb +bin/* +features/**/*.feature +LICENSE diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c1e0daf --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +## MAC OS +.DS_Store + +## TEXTMATE +*.tmproj +tmtags + +## EMACS +*~ +\#* +.\#* + +## VIM +*.swp + +## PROJECT::GENERAL +coverage +rdoc +pkg + +## PROJECT::SPECIFIC diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..7887d5b --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +-e ./yard_extensions.rb --no-private - *.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..07d0398 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2011 Ryan Jarvinen + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e6228a --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +#eventbrite-client.rb# + +##Description## +A tiny ruby-based http client for the Eventbrite API + +For the latest information on this project, take a look at: + +* [This project's source code repo](http://github.com/eventbrite/eventbrite-client.rb/) +* [The Eventbrite API documentation](http://developer.eventbrite.com/doc/) + +##Usage Examples## + +###Installation via rubygems ### + + gem install eventbrite-client + +###Loading the Eventbrite API Client library code### + + require eventbrite-client + +###Initializing the client### +Your API / Application key is required to initialize the client - http://eventbrite.com/api/key + +Set your user_key if you want to access private data - http://eventbrite.com/userkeyapi + + eb_auth_tokens = { app_key: 'YOUR_APP_KEY', + user_key: 'YOU_USER_KEY'} + eb_client = EventbriteClient.new(eb_auth_tokens) + +###Calling API methods### +See [Eventbrite's API method documentation](http://developer.eventbrite.com/doc/) for more information about the list of available client methods. + +Here is an example using the API's [user_list_events](http://developer.eventbrite.com/doc/users/user_list_events/) method: + + response = eb_client.user_list_events() + +The [event_get](http://developer.eventbrite.com/doc/events/event_get/) API call should look like this: + + response = eb_client.event_get({id: 1848891083}) + +### Widgets ### +Rendering an event in html as a [ticketWidget](http://www.eventbrite.com/t/how-to-use-ticket-widget) is easy: + + response = eb_client.event_get({id: 1848891083}) + widget_html = EventbriteWidgets::ticketWidget(response['event']) + +##Resources## +* API Documentation - +* API QuickStart Guide - +* Eventbrite Open Source - +* Eventbrite App Showcase - +* 0.3x source - +* 0.2x source - diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..f2a7e02 --- /dev/null +++ b/Rakefile @@ -0,0 +1,53 @@ +require 'rubygems' +require 'rake' + +begin + require 'jeweler' + Jeweler::Tasks.new do |gem| + gem.name = "eventbrite-client" + gem.summary = %Q{A tiny EventBrite API client} + gem.description = %Q{A with the EventBrite events service. (http://developer.eventbrite.com)} + gem.email = "ryan.jarvinen@gmail.com" + gem.homepage = "http://github.com/ryanjarvinen/eventbrite-client.rb" + gem.authors = ["Ryan Jarvinen"] + gem.add_development_dependency "rspec", "~> 1.3.0" + gem.add_dependency "httparty", "~> 0.7.0" + gem.add_dependency "tzinfo", "~> 0.3.22" + + # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings + end + Jeweler::GemcutterTasks.new +rescue LoadError + puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" +end + +require 'spec/rake/spectask' +Spec::Rake::SpecTask.new(:spec) do |spec| + spec.libs << 'lib' << 'spec' + spec.spec_files = FileList['spec/**/*_spec.rb'] +end + +Spec::Rake::SpecTask.new(:rcov) do |spec| + spec.libs << 'lib' << 'spec' + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true +end + +task :spec => :check_dependencies + +task :default => :irb + +require 'rake/rdoctask' +Rake::RDocTask.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "eventbrite-client #{version}" + rdoc.rdoc_files.include('README*') + rdoc.rdoc_files.include('lib/*.rb') +end + +desc "Runs irb with eventbrite-client lib" +task :irb do + sh "irb -r 'lib/eventbrite-client'" +end diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..1860db8 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 \ No newline at end of file diff --git a/eventbrite-client.gemspec b/eventbrite-client.gemspec new file mode 100644 index 0000000..40de447 --- /dev/null +++ b/eventbrite-client.gemspec @@ -0,0 +1,51 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{eventbrite-client} + s.version = "0.1.0" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Ryan Jarvinen"] + s.date = %q{2011-08-28} + s.description = %q{A tiny EventBrite API client. (http://developer.eventbrite.com)} + s.email = %q{ryan.jarvinen@gmail.com} + s.extra_rdoc_files = [ + "LICENSE", + "README.md" + ] + s.files = [ + ".document", + "LICENSE", + "README.md", + "Rakefile", + "VERSION", + "eventbrite-client.gemspec", + "lib/eventbrite-client.rb", + ] + s.homepage = %q{http://github.com/ryanjarvinen/eventbrite-client.rb} + s.require_paths = ["lib"] + s.rubygems_version = %q{1.6.2} + s.summary = %q{A tiny EventBrite API client} + + if s.respond_to? :specification_version then + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_development_dependency(%q, ["~> 1.3.0"]) + s.add_runtime_dependency(%q, ["~> 0.7.0"]) + s.add_runtime_dependency(%q, ["~> 0.3.22"]) + else + s.add_dependency(%q, ["~> 1.3.0"]) + s.add_dependency(%q, ["~> 0.7.0"]) + s.add_dependency(%q, ["~> 0.3.22"]) + end + else + s.add_dependency(%q, ["~> 1.3.0"]) + s.add_dependency(%q, ["~> 0.7.0"]) + s.add_dependency(%q, ["~> 0.3.22"]) + end +end + diff --git a/lib/eventbrite-client.rb b/lib/eventbrite-client.rb new file mode 100644 index 0000000..2690d07 --- /dev/null +++ b/lib/eventbrite-client.rb @@ -0,0 +1,70 @@ +require 'httparty' +class EventbriteClient + include HTTParty + base_uri 'https://www.eventbrite.com' + + def initialize( auth_tokens ) + @auth = {} + @data_type = 'json' + if auth_tokens.is_a? Hash + if auth_tokens.include? :access_token + # use oauth2 authentication tokens + self.class.headers 'Authorization' => "Bearer #{auth_tokens[:access_token]}" + elsif auth_tokens.include? :app_key + #use api_key OR api_key + user_key OR api_key+email+pass + if auth_tokens.include? :user_key + # read/write access on the user account associated with :user_key + @auth = {app_key: auth_tokens[:app_key], user_key: auth_tokens[:user_key]} + elsif auth_tokens.include?(:user) && auth_tokens.include?(:password) + # read/write access on the user account matching this login info + @auth = {app_key: auth_tokens[:app_key], user: auth_tokens[:user], :password => auth_tokens[:password]} + else + # read-only access to public data + @auth = {app_key: auth_tokens[:app_key]} + end + end + end + end + + # available API request methods are documented at: + # http://developer.eventbrite.com/doc + def method_request( method, params ) + #merge auth params into our request querystring + querystring = @auth.merge( params.is_a?(Hash) ? params : {} ) + resp = self.class.get("/#{@data_type}/#{method.to_s}",{query: querystring}) + if resp['error'] + raise RuntimeError, resp['error']['error_message'], caller[1..-1] + end + return resp + end + + def method_missing(method, *args, &block) + self.method_request(method, args[0]) + end +end + +class EventbriteWidgets + def self.ticketWidget(evnt) + "" + end + + def self.registrationWidget(evnt) + "" + end + + def self.calendarWidget(evnt) + "" + end + + def self.countdownWidget(evnt) + "" + end + + def self.buttonWidget(evnt) + "Register for #{evnt[" + end + + def self.linkWidget(evnt, text=nil, color='#000000') + "#{text || evnt['title']}" + end +end