-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gabe got tests working. working out events
- Loading branch information
Showing
11 changed files
with
295 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
--color --format nested |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1,16 @@ | |||
#!/usr/bin/env rake | #!/usr/bin/env rake | ||
require "bundler/gem_tasks" | require "bundler/gem_tasks" | ||
require 'rake' | |||
require 'rspec/core/rake_task' | |||
|
|||
namespace :spec do | |||
RSpec::Core::RakeTask.new(:normal) do |t| | |||
t.pattern ='spec/**/*_spec.rb' | |||
t.rcov = false | |||
end | |||
end | |||
|
|||
desc 'RSpec tests' | |||
task 'spec' => 'spec:normal' | |||
|
|||
task 'default' => 'spec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,15 @@ | |||
require "eventful/version" | require 'eventful/version' | ||
|
|
||
module Eventful | module Eventful | ||
# Your code goes here... | ENDPOINT = 'http://api.eventful.com/rest/' | ||
|
|||
class << self | |||
attr_accessor :api_key | |||
|
|||
end | |||
|
|||
end | end | ||
|
|||
require 'eventful/request' | |||
require 'eventful/response' | |||
require 'eventful/event' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
module Eventful | |||
|
|||
class Event | |||
|
|||
class << self | |||
|
|||
def search(options = {}) | |||
[].tap do |c| | |||
c.extend Response | |||
c << new | |||
end | |||
end | |||
|
|||
end | |||
|
|||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,100 @@ | |||
require 'faraday_middleware' | |||
|
|||
module Eventful | |||
## | |||
# Used by {Client} to execute HTTP requests against APIs. | |||
module Request | |||
FARADAY_OPTIONS = { | |||
:headers => { | |||
'Accept' => 'text/xml, application/xml; charset=utf-8', | |||
'User-Agent' => -> { 'eventful-ruby/%s (Rubygems; Ruby %s %s)' % [Eventful::VERSION, RUBY_VERSION, RUBY_PLATFORM] }.call | |||
}, | |||
:url => ::Eventful::ENDPOINT, | |||
:request => { | |||
:timeout => 5, | |||
:open_timeout => 5 | |||
} | |||
} | |||
|
|||
## | |||
# Builds and executes a `GET` request to the specified path with the | |||
# provided options. | |||
# | |||
# @param [String] path | |||
# @param [Hash] options | |||
# @return [Faraday::Response] | |||
def get(path = nil, options = {}) | |||
connection.get(path, options) | |||
end | |||
|
|||
## | |||
# Builds and executes a `POST` request to the specified path with the | |||
# provided options. | |||
# | |||
# @param [String] path | |||
# @param [Hash] options | |||
# @return [Faraday::Response] | |||
def post(path = nil, options = {}) | |||
connection.post(path, options) | |||
end | |||
|
|||
## | |||
# Builds and executes a `PUT` request to the specified path with the | |||
# provided options. | |||
# | |||
# @param [String] path | |||
# @param [Hash] options | |||
# @return [Faraday::Response] | |||
def put(path = nil, options = {}) | |||
connection.put(path, options) | |||
end | |||
|
|||
## | |||
# Builds and executes a `DELETE` request to the specified path with the | |||
# provided options. | |||
# | |||
# @param [String] path | |||
# @param [Hash] options | |||
# @return [Faraday::Response] | |||
def delete(path = nil, options = {}) | |||
connection.delete(path, options) | |||
end | |||
|
|||
## | |||
# Builds and returns a `Faraday::Connection` for executing HTTP requests. | |||
# | |||
# @return [Faraday::Connection] | |||
def connection | |||
@connection ||= Faraday::Connection.new(FARADAY_OPTIONS) do |c| | |||
c.response :xml, :content_type => /\bxml$/ | |||
c.adapter(Faraday.default_adapter) | |||
end | |||
end | |||
|
|||
## | |||
# Returns a formatted string to be used as the user agent when making | |||
# requests. | |||
# | |||
# @return [String] | |||
# A user agent describing the environment | |||
# | |||
# @example | |||
# client.user_agent | |||
# # => "eventful-ruby/0.1.0 (Rubygems; Ruby 1.9.3 x86_64-darwin11.4.0)" | |||
def user_agent | |||
'eventful-ruby/%s (Rubygems; Ruby %s %s)' % [Eventful::VERSION, RUBY_VERSION, RUBY_PLATFORM] | |||
end | |||
|
|||
## | |||
# Returns the provided object and attaches the response, additionally | |||
# specifying whether the request returned a successful response. | |||
def respond_with(object, response = nil, options = {}, &block) | |||
object.tap do |o| | |||
o.extend(Response) | |||
o.raw_response = response | |||
o.success = options.has_key?(:success) ? options[:success] : true | |||
yield(o) if block_given? | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
module Eventful | |||
module Response | |||
attr_accessor :raw_response | |||
attr_writer :success | |||
|
|||
def success? | |||
!!@success | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
require 'spec_helper' | |||
|
|||
describe Eventful::Event do | |||
|
|||
describe '.search' do | |||
context 'when coordinates are provided' do | |||
subject { Eventful::Event.search(latitude: '123', longitude: '-123') } | |||
|
|||
it 'returns an array of events' do | |||
subject.first.should be_kind_of(Eventful::Event) | |||
end | |||
|
|||
# its(:response) { should be_success } | |||
end | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,89 @@ | |||
require 'spec_helper' | |||
|
|||
describe Eventful::Request do | |||
let(:http) do | |||
Class.new do | |||
include Eventful::Request | |||
end | |||
end | |||
|
|||
let(:url) { %r{^http://api.eventful.com/rest} } | |||
|
|||
let(:client) { http.new } | |||
|
|||
subject { client } | |||
|
|||
after(:each) do | |||
WebMock.reset! | |||
end | |||
|
|||
context '#get' do | |||
subject { client.get } | |||
|
|||
before(:each) do | |||
WebMock.stub_request(:any, /.*/) | |||
end | |||
|
|||
it 'should execute a GET request' do | |||
subject | |||
WebMock.should have_requested(:get, url) | |||
end | |||
end | |||
|
|||
context '#post' do | |||
subject { client.post(nil, 'something') } | |||
|
|||
before(:each) do | |||
WebMock.stub_request(:any, url) | |||
end | |||
|
|||
it 'should execute a POST request with the given data' do | |||
subject | |||
WebMock.should have_requested(:post, url).with(:body => 'something') | |||
end | |||
end | |||
|
|||
context '#put' do | |||
subject { client.put(nil, 'something') } | |||
|
|||
before(:each) do | |||
WebMock.stub_request(:any, url) | |||
end | |||
|
|||
it 'should execute a PUT request with the given data' do | |||
subject | |||
WebMock.should have_requested(:put, url).with(:body => 'something') | |||
end | |||
end | |||
|
|||
context '#delete' do | |||
subject { client.delete } | |||
|
|||
before(:each) do | |||
WebMock.stub_request(:any, url) | |||
end | |||
|
|||
it 'should execute a DELETE request' do | |||
subject | |||
WebMock.should have_requested(:delete, url) | |||
end | |||
end | |||
|
|||
context '#connection' do | |||
it 'should accept XML responses' do | |||
Faraday::Connection.should_receive(:new).with(hash_including(:headers => hash_including('Accept' => 'text/xml, application/xml; charset=utf-8'))) | |||
subject.connection | |||
end | |||
|
|||
it 'should set the user agent' do | |||
Faraday::Connection.should_receive(:new).with(hash_including(:headers => hash_including('User-Agent' => subject.user_agent))) | |||
subject.connection | |||
end | |||
end | |||
|
|||
context '#user_agent' do | |||
it 'should build a user agent containing the release, Ruby, and platform versions' do | |||
subject.user_agent.should =~ %r{^eventful-ruby/[0-9\.]+ \(Rubygems; Ruby [0-9\.]+ .+\)$} | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
require 'spec_helper' | |||
|
|||
describe Eventful do | |||
|
|||
describe '.api_key' do | |||
it 'is accessible' do | |||
subject.api_key = 'foo' | |||
subject.api_key.should == 'foo' | |||
end | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
require 'rubygems' | |||
require 'bundler' | |||
begin | |||
Bundler.setup(:default, :development, :test) | |||
rescue Bundler::BundlerError => e | |||
$stderr.puts e.message | |||
$stderr.puts "Run `bundle install` to install missing gems" | |||
exit e.status_code | |||
end | |||
|
|||
require 'rspec/autorun' | |||
require 'webmock/rspec' | |||
|
|||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | |||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | |||
require 'eventful-ruby' | |||
|
|||
# Requires supporting files with custom matchers and macros, etc, | |||
# in ./support/ and its subdirectories. | |||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} |