Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanj committed Sep 1, 2011
0 parents commit 1b0fdd8
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .document
@@ -0,0 +1,5 @@
README.rdoc
lib/**/*.rb
bin/*
features/**/*.feature
LICENSE
21 changes: 21 additions & 0 deletions .gitignore
@@ -0,0 +1,21 @@
## MAC OS
.DS_Store

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## VIM
*.swp

## PROJECT::GENERAL
coverage
rdoc
pkg

## PROJECT::SPECIFIC
1 change: 1 addition & 0 deletions .yardopts
@@ -0,0 +1 @@
-e ./yard_extensions.rb --no-private - *.md
20 changes: 20 additions & 0 deletions 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.
53 changes: 53 additions & 0 deletions 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 - <http://developer.eventbrite.com/doc/>
* API QuickStart Guide - <http://developer.eventbrite.com/doc/getting-started/>
* Eventbrite Open Source - <http://eventbrite.github.com/>
* Eventbrite App Showcase - <http://eventbrite.appstores.com/>
* 0.3x source - <http://github.com/eventbrite/eventbrite-client-py/>
* 0.2x source - <http://github.com/mtai/eventbrite/>
53 changes: 53 additions & 0 deletions 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
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
0.1.0
51 changes: 51 additions & 0 deletions 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<rspec>, ["~> 1.3.0"])
s.add_runtime_dependency(%q<httparty>, ["~> 0.7.0"])
s.add_runtime_dependency(%q<tzinfo>, ["~> 0.3.22"])
else
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
s.add_dependency(%q<httparty>, ["~> 0.7.0"])
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
end
else
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
s.add_dependency(%q<httparty>, ["~> 0.7.0"])
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
end
end

70 changes: 70 additions & 0 deletions 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)
"<div style='width:100%; text-align:left;' ><iframe src='http://www.eventbrite.com/tickets-external?eid=#{ evnt["id"]}&ref=etckt' frameborder='0' height='192' width='100%' vspace='0' hspace='0' marginheight='5' marginwidth='5' scrolling='auto' allowtransparency='true'></iframe><div style='font-family:Helvetica, Arial; font-size:10px; padding:5px 0 5px; margin:2px; width:100%; text-align:left;'><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com/r/etckt'>Online Ticketing</a><span style='color:#ddd;'> for </span><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com/event/#{evnt["id"]}?ref=etckt'>#{evnt["title"]}</a><span style='color:#ddd;'> powered by </span><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com?ref=etckt'>Eventbrite</a></div></div>"
end

def self.registrationWidget(evnt)
"<div style='width:100%; text-align:left;'><iframe src='http://www.eventbrite.com/event/#{evnt['id']}?ref=eweb' frameborder='0' height='1000' width='100%' vspace='0' hspace='0' marginheight='5' marginwidth='5' scrolling='auto' allowtransparency='true'></iframe><div style='font-family:Helvetica, Arial; font-size:10px; padding:5px 0 5px; margin:2px; width:100%; text-align:left;'><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com/r/eweb'>Online Ticketing</a><span style='color:#ddd;'> for </span><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com/event/#{evnt['id']}?ref=eweb'>#{evnt['title']}</a><span style='color:#ddd;'> powered by </span><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com?ref=eweb'>Eventbrite</a></div></div>"
end

def self.calendarWidget(evnt)
"<div style='width:195px; text-align:center;'><iframe src='http://www.eventbrite.com/calendar-widget?eid=#{evnt['id']}' frameborder='0' height='382' width='195' marginheight='0' marginwidth='0' scrolling='no' allowtransparency='true'></iframe><div style='font-family:Helvetica, Arial; font-size:10px; padding:5px 0 5px; margin:2px; width:195px; text-align:center;'><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com/r/ecal'>Online event registration</a><span style='color:#ddd;'> powered by </span><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com?ref=ecal'>Eventbrite</a></div></div>"
end

def self.countdownWidget(evnt)
"<div style='width:195px; text-align:center;'><iframe src='http://www.eventbrite.com/countdown-widget?eid=#{evnt['id']}' frameborder='0' height='479' width='195' marginheight='0' marginwidth='0' scrolling='no' allowtransparency='true'></iframe><div style='font-family:Helvetica, Arial; font-size:10px; padding:5px 0 5px; margin:2px; width:195px; text-align:center;'><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com/r/ecount'>Online event registration</a><span style='color:#ddd;'> for </span><a style='color:#ddd; text-decoration:none;' target='_blank' href='http://www.eventbrite.com/event/#{evnt['id']}?ref=ecount'>#{evnt['title']}</a></div></div>"
end

def self.buttonWidget(evnt)
"<a href='http://www.eventbrite.com/event/#{evnt['id']}?ref=ebtn' target='_blank'><img border='0' src='http://www.eventbrite.com/registerbutton?eid=#{evnt['id']}' alt='Register for #{evnt['title']} on Eventbrite' /></a>"
end

def self.linkWidget(evnt, text=nil, color='#000000')
"<a href='http://www.eventbrite.com/event/#{evnt["id"]}?ref=elink' target='_blank' style='color:#{color};'>#{text || evnt['title']}</a>"
end
end

0 comments on commit 1b0fdd8

Please sign in to comment.