jibeset 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 'ruby-1.9.2@ruby-jibeset'
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,37 @@
1
+ Jibeset
2
+ ====
3
+
4
+ Configure
5
+ ---------
6
+ ```ruby
7
+ # Configure your client with the credentials you got from
8
+ # registering your application at jibeset.heroku.com/oauth_clients
9
+ Jibeset.configure do |config|
10
+ config.client_id = 'YOUR_CLIENT_ID'
11
+ config.client_secret = 'YOUR_CLIENT_SECRET'
12
+ config.endpoint = 'http://jibeset.heroku.com/'
13
+ config.oauth_callback = 'http://yourapp.example.com/oauth_callback'
14
+ end
15
+ ```
16
+
17
+ Authorization Flow
18
+ ------------------
19
+ ```ruby
20
+ # Get an authorization code from the JibeSet OAuth Provider
21
+ # Pretend this is in a sinatra app
22
+ get '/auth/oauth' do
23
+ redirect Jibeset.authorize_url
24
+ end
25
+
26
+ # Use the authorization code to get an access code
27
+ # This will be the action that your callback URL redirects to
28
+ get '/auth/oauth/callback' do
29
+ response = Jibeset.get_access_token(params[:code], :redirect_uri => oauth_callback)
30
+ token = JSON.parse(response.body)["access_token"]
31
+ # Store the access token in the session so you can get it later to sign
32
+ # subsuquent requests.
33
+ session[:jibeset_token] = token
34
+ # Create a client
35
+ client = Jibeset.client(:access_token => token)
36
+ client.me # => returns authenticated user
37
+ end
@@ -0,0 +1,14 @@
1
+ task :default => :test
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ desc "Open an irb session preloaded with this library"
11
+ task :console do
12
+ sh "irb -rubygems -r ./lib/jibeset.rb"
13
+ end
14
+
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jibeset/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.add_development_dependency('ruby-debug19')
6
+ s.add_development_dependency('geminabox')
7
+ s.add_runtime_dependency('faraday', '>= 0.7')
8
+ s.add_runtime_dependency('faraday_middleware')
9
+ s.add_runtime_dependency('oauth2')
10
+ s.add_runtime_dependency('multi_json')
11
+ s.add_runtime_dependency('hashie', '>= 0.4.0')
12
+ s.add_runtime_dependency('yajl-ruby')
13
+ s.add_development_dependency('ruby-debug19')
14
+ s.add_development_dependency('geminabox')
15
+ s.add_development_dependency('minitest')
16
+ s.authors = ["Claude Nix"]
17
+ s.description = %q{A Ruby wrapper for the jibeset REST and Search APIs}
18
+ s.email = ['claude@seadated.com']
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.files = `git ls-files`.split("\n")
21
+ s.homepage = 'https://github.com/cnix/ruby-jibeset'
22
+ s.name = 'jibeset'
23
+ s.platform = Gem::Platform::RUBY
24
+ s.require_paths = ['lib']
25
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
26
+ s.rubyforge_project = s.name
27
+ s.summary = %q{Ruby wrapper for the jibeset API}
28
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
+ s.version = Jibeset::VERSION.dup
30
+ end
31
+
@@ -0,0 +1,36 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Request::OAuth2 < Faraday::Middleware
7
+ def call(env)
8
+
9
+ if env[:method] == :get or env[:method] == :delete
10
+ env[:url].query_values = {} if env[:url].query_values.nil?
11
+ if @access_token and not env[:url].query_values["client_secret"]
12
+ env[:url].query_values = env[:url].query_values.merge(:access_token => @access_token)
13
+ env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
14
+ elsif @client_id
15
+ env[:url].query_values = env[:url].query_values.merge(:client_id => @client_id)
16
+ end
17
+ else
18
+ if @access_token and not env[:body] && env[:body][:client_secret]
19
+ env[:body] = {} if env[:body].nil?
20
+ env[:body] = env[:body].merge(:access_token => @access_token)
21
+ env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
22
+ elsif @client_id
23
+ env[:body] = env[:body].merge(:client_id => @client_id)
24
+ end
25
+ end
26
+
27
+ @app.call env
28
+ end
29
+
30
+ def initialize(app, client_id, access_token=nil)
31
+ @app = app
32
+ @client_id = client_id
33
+ @access_token = access_token
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../jibeset/error', __FILE__)
2
+ require File.expand_path('../jibeset/configuration', __FILE__)
3
+ require File.expand_path('../jibeset/api', __FILE__)
4
+ require File.expand_path('../jibeset/client', __FILE__)
5
+
6
+ module Jibeset
7
+ extend Configuration
8
+
9
+ # Alias for Jibeset::Client.new
10
+ #
11
+ # @return [Jibeset::Client]
12
+ def self.client(options={})
13
+ Jibeset::Client.new(options)
14
+ end
15
+
16
+ # Delegate to Jibeset::Client
17
+ def self.method_missing(method, *args, &block)
18
+ return super unless client.respond_to?(method)
19
+ client.send(method, *args, &block)
20
+ end
21
+
22
+ # Delegate to Jibeset::Client
23
+ def self.respond_to?(method)
24
+ return client.respond_to?(method) || super
25
+ end
26
+ end
27
+
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+ require File.expand_path('../oauth', __FILE__)
4
+
5
+ module Jibeset
6
+ # @private
7
+ class API
8
+ # @private
9
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
10
+
11
+ # Creates a new API
12
+ def initialize(options={})
13
+ options = Jibeset.options.merge(options)
14
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ include Connection
20
+ include Request
21
+ include OAuth
22
+ end
23
+ end
24
+
@@ -0,0 +1,18 @@
1
+ module Jibeset
2
+ # Wrapper for the Jibeset API
3
+ #
4
+ # @note All methods have been separated into modules and follow the same grouping used in {TODO:doc_URL the Jibeset API Documentation}.
5
+ # @see TODO:doc_url
6
+ class Client < API
7
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
8
+
9
+ include Jibeset::Client::Utils
10
+ include Jibeset::Client::Users
11
+ include Jibeset::Client::Events
12
+ include Jibeset::Client::Fleets
13
+ include Jibeset::Client::Entries
14
+ include Jibeset::Client::Boat
15
+ include Jibeset::Client::Search
16
+ end
17
+ end
18
+
@@ -0,0 +1,29 @@
1
+ module Jibeset
2
+ class Client
3
+ module Boat
4
+
5
+ def boats(payload={})
6
+ if payload[:boat]
7
+ post('/boats', payload)
8
+ elsif payload[:user_id]
9
+ get("/users/#{payload[:user_id]}/boats")
10
+ else
11
+ get("/boats")
12
+ end
13
+ end
14
+
15
+ def boat(payload)
16
+ get("/boats/#{payload[:id]}")
17
+ end
18
+
19
+ def update_boat(payload)
20
+ put("/boats/#{payload[:boat][:id]}", payload)
21
+ end
22
+
23
+ def destroy_boat(payload)
24
+ delete("/boats/#{payload[:id]}")
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ module Jibeset
2
+ class Client
3
+ module Entries
4
+
5
+ def register(payload)
6
+ post("/events/#{payload[:event_id]}/entries", payload)
7
+ end
8
+
9
+ def entries(payload={})
10
+ get("/events/#{payload[:event_id]}/entries")
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,40 @@
1
+ module Jibeset
2
+ class Client
3
+ module Events
4
+
5
+ def events
6
+ get("/events")
7
+ end
8
+
9
+ def event(payload)
10
+ get("/events/#{payload[:id]}")
11
+ end
12
+
13
+ def event_entries(payload)
14
+ get("/events/#{payload[:id]}/entries")
15
+ end
16
+
17
+ def event_fleets(payload)
18
+ get("/events/#{payload[:id]}/fleets")
19
+ end
20
+
21
+ def create_event(payload)
22
+ post("/events", payload)
23
+ end
24
+
25
+ def update_event(payload)
26
+ put("/events/#{payload['id']}", payload)
27
+ end
28
+
29
+ def destroy_event(payload)
30
+ delete("/events/#{payload['id']}")
31
+ end
32
+
33
+ def register_entry(payload)
34
+ post("/events/#{payload[:event_id]}/entries", payload)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,27 @@
1
+ module Jibeset
2
+ class Client
3
+ module Fleets
4
+
5
+ def fleets(payload)
6
+ get("/events/#{payload[:event_id]}/fleets")
7
+ end
8
+
9
+ def fleet(payload)
10
+ get("/events/#{payload[:event_id]}/fleets/#{payload[:id]}")
11
+ end
12
+
13
+ def create_fleet(payload)
14
+ post("/events/#{payload[:event_id]}/fleets", payload)
15
+ end
16
+
17
+ def update_fleet(payload)
18
+ put("/events/#{payload[:event_id]}/fleets/#{payload[:id]}", payload)
19
+ end
20
+
21
+ def destroy_fleet(payload)
22
+ delete("/events/#{payload[:event_id]}/fleets/#{payload[:id]}")
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module Jibeset
2
+ class Client
3
+ module Search
4
+
5
+ def search(query)
6
+ query = { q: query }
7
+ get('/search', query)
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ module Jibeset
2
+ class Client
3
+ module Users
4
+
5
+ def create_user(payload)
6
+ post("/users", payload)
7
+ end
8
+
9
+ def user(payload)
10
+ get("/users/#{payload[:id]}")
11
+ end
12
+
13
+ def update_user(payload)
14
+ put("/users/#{payload[:id]}", payload)
15
+ end
16
+
17
+ def destroy_user(payload)
18
+ delete("/users/#{payload[:id]}")
19
+ end
20
+
21
+ def me
22
+ get("/me")
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module Jibeset
2
+ class Client
3
+ # @private
4
+ module Utils
5
+ private
6
+
7
+ # Returns the configured user name or the user name of the authenticated user
8
+ #
9
+ # @return [String]
10
+ def get_username
11
+ @user_name ||= self.user.username
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,97 @@
1
+ require 'faraday'
2
+ require File.expand_path('../version', __FILE__)
3
+
4
+ module Jibeset
5
+ # Defines constants and methods related to configuration
6
+ module Configuration
7
+ # An array of valid keys in the options hash when configuring a {Jibeset::API}
8
+ VALID_OPTIONS_KEYS = [
9
+ :adapter,
10
+ :client_id,
11
+ :client_secret,
12
+ :access_token,
13
+ :endpoint,
14
+ :format,
15
+ :user_agent,
16
+ :oauth_callback,
17
+ :proxy
18
+ ].freeze
19
+
20
+ # An array of valid request/response formats
21
+ #
22
+ # @note Not all methods support the XML format.
23
+ VALID_FORMATS = [
24
+ :json].freeze
25
+
26
+ # The adapter that will be used to connect if none is set
27
+ #
28
+ # @note The default faraday adapter is Net::HTTP.
29
+ DEFAULT_ADAPTER = Faraday.default_adapter
30
+
31
+ # By default, don't set an application ID
32
+ DEFAULT_CLIENT_ID = nil
33
+
34
+ # By default, don't set an application secret
35
+ DEFAULT_CLIENT_SECRET = nil
36
+
37
+ # By default, don't set an application redirect uri
38
+ DEFAULT_REDIRECT_URI = nil
39
+
40
+ # By default, don't set a user access token
41
+ DEFAULT_ACCESS_TOKEN = nil
42
+
43
+ # By default, don't set an oauth callback url
44
+ DEFAULT_OAUTH_CALLBACK = nil
45
+
46
+ # The endpoint that will be used to connect if none is set
47
+ #
48
+ # @note There is no reason to use any other endpoint at this time
49
+ DEFAULT_ENDPOINT = 'http://jibeset.heroku.com/'.freeze
50
+
51
+ # The response format appended to the path and sent in the 'Accept' header if none is set
52
+ #
53
+ # @note JSON is the only available format at this time
54
+ DEFAULT_FORMAT = :json
55
+
56
+ # By default, don't use a proxy server
57
+ DEFAULT_PROXY = nil
58
+
59
+ # The user agent that will be sent to the API endpoint if none is set
60
+ DEFAULT_USER_AGENT = "Jibeset Ruby Gem #{Jibeset::VERSION}".freeze
61
+
62
+ # @private
63
+ attr_accessor *VALID_OPTIONS_KEYS
64
+
65
+ # When this module is extended, set all configuration options to their default values
66
+ def self.extended(base)
67
+ base.reset
68
+ end
69
+
70
+ # Convenience method to allow configuration options to be set in a block
71
+ def configure
72
+ yield self
73
+ end
74
+
75
+ # Create a hash of options and their values
76
+ def options
77
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
78
+ option.merge!(key => send(key))
79
+ end
80
+ end
81
+
82
+ # Reset all configuration options to defaults
83
+ def reset
84
+ self.adapter = DEFAULT_ADAPTER
85
+ self.client_id = DEFAULT_CLIENT_ID
86
+ self.client_secret = DEFAULT_CLIENT_SECRET
87
+ self.access_token = DEFAULT_ACCESS_TOKEN
88
+ self.oauth_callback = DEFAULT_OAUTH_CALLBACK
89
+ self.endpoint = DEFAULT_ENDPOINT
90
+ self.format = DEFAULT_FORMAT
91
+ self.user_agent = DEFAULT_USER_AGENT
92
+ self.proxy = DEFAULT_PROXY
93
+ end
94
+
95
+ end
96
+ end
97
+
@@ -0,0 +1,33 @@
1
+ require 'faraday_middleware'
2
+ Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
3
+
4
+ module Jibeset
5
+ # @private
6
+ module Connection
7
+ private
8
+
9
+ def connection(raw=false)
10
+ options = {
11
+ :headers => {'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
12
+ :proxy => proxy,
13
+ :ssl => {:verify => false},
14
+ :url => endpoint
15
+ }
16
+
17
+ Faraday::Connection.new(options) do |builder|
18
+ builder.use Faraday::Request::OAuth2, client_id, access_token
19
+ builder.use Faraday::Request::JSON
20
+
21
+ # It seems that I don't understand the way Faraday likes things ordered.
22
+ # Mashify needs a ruby object to mash, so the response needs to run
23
+ # through ParseJson first. If you order them that way, Mashify gets
24
+ # JSON, and can't mash it. Am I crazy?
25
+ builder.use Faraday::Response::Mashify unless raw
26
+ builder.use Faraday::Response::ParseJson # always deal with json
27
+
28
+ builder.adapter(adapter)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,23 @@
1
+ module Jibeset
2
+ # Custom error class for rescuing from all Instagram errors
3
+ class Error < StandardError; end
4
+
5
+ # Raised when Instagram returns the HTTP status code 400
6
+ class BadRequest < Error; end
7
+
8
+ # Raised when Instagram returns the HTTP status code 404
9
+ class NotFound < Error; end
10
+
11
+ # Raised when Instagram returns the HTTP status code 500
12
+ class InternalServerError < Error; end
13
+
14
+ # Raised when Instagram returns the HTTP status code 503
15
+ class ServiceUnavailable < Error; end
16
+
17
+ # Raised when a subscription payload hash is invalid
18
+ class InvalidSignature < Error; end
19
+
20
+ # Raised when the configuration is invalid
21
+ class InvalidConfiguration < Error; end
22
+ end
23
+
@@ -0,0 +1,30 @@
1
+ module Jibeset
2
+ # Defines HTTP request methods
3
+ module OAuth
4
+ # Return URL for OAuth authorization
5
+ def authorize_url(options={})
6
+ options[:response_type] ||= "code"
7
+ options[:redirect_uri] = oauth_callback
8
+ authorize_path = options[:authorize_path] || "/oauth/authorize/"
9
+ params = access_token_params.merge(options)
10
+ connection.build_url(authorize_path, params).to_s
11
+ end
12
+
13
+ # Return an access token from authorization
14
+ def get_access_token(code, options={})
15
+ options[:grant_type] ||= "authorization_code"
16
+ options[:redirect_uri] = oauth_callback
17
+ params = access_token_params.merge(options)
18
+ post("/oauth/token/", params.merge(:code => code), false, unformatted=true)
19
+ end
20
+
21
+
22
+ private
23
+
24
+ def access_token_params
25
+ { :client_id => client_id,
26
+ :client_secret => client_secret }
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,47 @@
1
+ module Jibeset
2
+ # Defines HTTP request methods
3
+ module Request
4
+ # Perform an HTTP GET request
5
+ def get(path, options={}, raw=false, unformatted=false)
6
+ request(:get, path, options, raw, unformatted)
7
+ end
8
+
9
+ # Perform an HTTP POST request
10
+ def post(path, options={}, raw=false, unformatted=false)
11
+ request(:post, path, options, raw, unformatted)
12
+ end
13
+
14
+ # Perform an HTTP PUT request
15
+ def put(path, options={}, raw=false, unformatted=false)
16
+ request(:put, path, options, raw, unformatted)
17
+ end
18
+
19
+ # Perform an HTTP DELETE request
20
+ def delete(path, options={}, raw=false, unformatted=false)
21
+ request(:delete, path, options, raw, unformatted)
22
+ end
23
+
24
+ private
25
+
26
+ # Perform an HTTP request
27
+ def request(method, path, options, raw=false, unformatted=false)
28
+ response = connection(raw).send(method) do |request|
29
+ path = formatted_path(path) unless unformatted
30
+ case method
31
+ when :get, :delete
32
+ request.url(path, options)
33
+ when :post, :put
34
+ request.path = path
35
+ request.body = options unless options.empty?
36
+ end
37
+ end
38
+ raw ? response : response.body
39
+ end
40
+
41
+ def formatted_path(path)
42
+ [path, format].compact.join('.')
43
+ end
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,4 @@
1
+ module Jibeset
2
+ VERSION = '0.2'.freeze unless defined?(::Jibeset::VERSION)
3
+ end
4
+
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ class EventTest < Jibeset::Test
4
+
5
+ def setup
6
+ @jibeset = Jibeset.client
7
+ @jibeset.stubs = Faraday::Adapter::Test::Stubs.new
8
+ end
9
+
10
+ def test_events_should_return_events
11
+ @jibeset.stubs.get('/events.json') { [200, {}, '{"events":[]}'] }
12
+ refute_nil @jibeset.events
13
+ end
14
+
15
+ def test_event_entries_should_return_entries
16
+
17
+ end
18
+
19
+ def test_create_event_should_create_event
20
+ payload = { :name => 'tybee', :event_type => 'series' }
21
+ @jibeset.stubs.post('/events.json') { [200,{},Yajl.dump(payload)] }
22
+ client = @jibeset.create_event(payload)
23
+
24
+ assert_equal Yajl.dump(payload), client
25
+ end
26
+
27
+ def test_update_event_should_update_event
28
+
29
+ end
30
+
31
+ def test_destroy_event_should_destroy_event
32
+
33
+ end
34
+
35
+ def test_register_entry
36
+
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ class UsersTest < Jibeset::Test
4
+
5
+ def setup
6
+ # user = {:username => 'cnix', :id => 1}
7
+
8
+ # client = Faraday.new do |builder|
9
+ # builder.adapter :test, @stubs do |stub|
10
+ # stub.get('/users/#{user[:username]}.json') {[ 200, {}, Yajl.dump(user) ]}
11
+ # end
12
+ # end
13
+
14
+ @client = Jibeset.client
15
+ @client.stubs = Faraday::Adapter::Test::Stubs.new
16
+ # client.user = user
17
+
18
+ # client = Jibeset.client
19
+ # client.stubs = Faraday::Adapter::Test::Stubs.new
20
+ # @client.stubs.get("/users/*.json") { [ 200, {}, Yajl.dump(user) ] }
21
+ # # debugger
22
+ # @user = @client.user(:username => 'cnix')
23
+ # @user.stubs = Faraday::Adapter::Test::Stubs.new
24
+ # @events = []
25
+ end
26
+
27
+ def test_me_should_get_authenticated_user_for_client
28
+ response = '{"username":"cnix", "email":"claude@seadated.com"}'
29
+ @client.stubs.get('/me.json') { [200, {}, response] }
30
+
31
+ assert_equal response, @client.me
32
+ end
33
+
34
+ # def test_events_should_return_events
35
+ # @jibeset.stubs.get('/events.json') { [200, {}, '{"events":[]}'] }
36
+ # assert_not_nil @jibeset.events
37
+ # end
38
+
39
+ # def test_create_event_should_create_event
40
+ # payload = { :name => 'tybee', :event_type => 'series' }
41
+ # @jibeset.stubs.post('/events.json') { [200,{},Yajl.dump(payload)] }
42
+ # client = @jibeset.create_event(payload)
43
+ #
44
+ # assert_equal Yajl.dump(payload), client
45
+ # end
46
+
47
+ # def test_events_gets_events_for_user
48
+ # @user.stubs.get("/#{@user.username}/events.json") { [200, {}, Yajl.dump(@events) ] }
49
+ # events = @user.events
50
+ # assert_equal Yajl.dump(events), @events
51
+ # end
52
+ end
53
+
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class ConfigurationTest < Jibeset::Test
4
+
5
+ def setup
6
+ @valid_config = Jibeset::Test.valid_config
7
+ end
8
+
9
+ def test_valid_options
10
+ @valid_config.call
11
+ Jibeset::Configuration::VALID_OPTIONS_KEYS.each do |key|
12
+ assert Jibeset.options.include? key
13
+ end
14
+ end
15
+
16
+ def test_configure
17
+ @valid_config.call
18
+ assert_equal Jibeset.oauth_callback, nil
19
+ end
20
+
21
+ def test_reset
22
+ Jibeset.reset
23
+ assert_equal nil, Jibeset.oauth_callback
24
+ end
25
+
26
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class TestOAuth < Jibeset::Test
4
+
5
+ def setup
6
+ @valid_config = Jibeset::Test.valid_config
7
+
8
+ @jibeset = Jibeset.client
9
+ @jibeset.stubs = Faraday::Adapter::Test::Stubs.new
10
+ end
11
+
12
+ end
@@ -0,0 +1,122 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/mock'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'jibeset'
7
+
8
+ #warn "#{__FILE__}:#{__LINE__}: version info: #{Jibeset::VERSION_INFO.inspect}"
9
+
10
+ module Jibeset
11
+ class Test < MiniTest::Spec
12
+ def self.valid_config
13
+ -> {
14
+ Jibeset.configure do |config|
15
+ Jibeset.adapter = :net_http
16
+ Jibeset.client_id = nil
17
+ Jibeset.client_secret = nil
18
+ Jibeset.access_token = nil
19
+ Jibeset.oauth_callback = nil
20
+ Jibeset.endpoint = 'http://jibeset.heroku.com/'
21
+ Jibeset.format = 'json'
22
+ Jibeset.user_agent = 'Jibeset Ruby Gem 0.1'
23
+ Jibeset.proxy = 'wtf'
24
+ end
25
+ }
26
+ end
27
+ end
28
+
29
+ class API
30
+ attr_accessor :stubs
31
+
32
+ def connection(raw=false)
33
+ options = {
34
+ :headers => {'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
35
+ :proxy => proxy,
36
+ :ssl => {:verify => false},
37
+ :url => endpoint,
38
+ :client_id => client_id,
39
+ :access_token => access_token
40
+ }
41
+
42
+ Faraday.new(options) do |connection|
43
+ connection.request :json
44
+ connection.adapter :test, @stubs
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+
52
+ #### test
53
+ #
54
+ # def flunk(msg=nil)
55
+ # def pass(msg=nil)
56
+ # def skip(msg=nil, bt=caller)
57
+ #
58
+ # assert(test, msg=nil)
59
+ # assert_block(msg=nil)
60
+ # assert_empty(obj, msg=nil)
61
+ # assert_equal(exp, act, msg=nil)
62
+ # assert_in_delta(exp, act, delta=0.001, msg=nil)
63
+ # assert_in_epsilon(a, b, epsilon=0.001, msg=nil)
64
+ # assert_includes(collection, obj, msg=nil)
65
+ # assert_instance_of(klass, obj, msg=nil)
66
+ # assert_kind_of(klass, obj, msg=nil)
67
+ # assert_match(exp, act, msg=nil)
68
+ # assert_nil(obj, msg=nil)
69
+ # assert_operator(o1, op, o2, msg=nil)
70
+ # assert_raises(*exp)
71
+ # assert_respond_to(obj, meth, msg=nil)
72
+ # assert_same(exp, act, msg=nil)
73
+ # assert_send(send_ary, msg=nil)
74
+ # assert_throws(sym, msg=nil)
75
+ #
76
+ # refute(test, msg=nil)
77
+ # refute_empty(obj, msg=nil)
78
+ # refute_equal(exp, act, msg=nil)
79
+ # refute_in_delta(exp, act, delta=0.001, msg=nil)
80
+ # refute_in_epsilon(a, b, epsilon=0.001, msg=nil)
81
+ # refute_includes(collection, obj, msg=nil)
82
+ # refute_instance_of(klass, obj, msg=nil)
83
+ # refute_kind_of(klass, obj, msg=nil)
84
+ # refute_match(exp, act, msg=nil)
85
+ # refute_nil(obj, msg=nil)
86
+ # refute_operator(o1, op, o2, msg=nil)
87
+ # refute_respond_to(obj, meth, msg=nil)
88
+ # refute_same(exp, act, msg=nil)
89
+ #
90
+ #### spec
91
+ #
92
+ # must_be_close_to
93
+ # must_be_empty
94
+ # must_be_instance_of
95
+ # must_be_kind_of
96
+ # must_be_nil
97
+ # must_be_same_as
98
+ # must_be_within_delta
99
+ # must_be_within_epsilon
100
+ # must_equal
101
+ # must_include
102
+ # must_match
103
+ # must_raise
104
+ # must_respond_to
105
+ # must_send
106
+ # must_throw
107
+ #
108
+ # wont_be_close_to
109
+ # wont_be_empty
110
+ # wont_be_instance_of
111
+ # wont_be_kind_of
112
+ # wont_be_nil
113
+ # wont_be_same_as
114
+ # wont_be_within_delta
115
+ # wont_be_within_epsilon
116
+ # wont_equal
117
+ # wont_include
118
+ # wont_match
119
+ # wont_raise
120
+ # wont_respond_to
121
+ # wont_send
122
+ # wont_throw
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jibeset
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.2"
6
+ platform: ruby
7
+ authors:
8
+ - Claude Nix
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-12-08 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ruby-debug19
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: geminabox
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: faraday
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0.7"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: faraday_middleware
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: oauth2
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :runtime
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: multi_json
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :runtime
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: hashie
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 0.4.0
91
+ type: :runtime
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: yajl-ruby
95
+ prerelease: false
96
+ requirement: &id008 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ type: :runtime
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: ruby-debug19
106
+ prerelease: false
107
+ requirement: &id009 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ type: :development
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: geminabox
117
+ prerelease: false
118
+ requirement: &id010 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ type: :development
125
+ version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: minitest
128
+ prerelease: false
129
+ requirement: &id011 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: "0"
135
+ type: :development
136
+ version_requirements: *id011
137
+ description: A Ruby wrapper for the jibeset REST and Search APIs
138
+ email:
139
+ - claude@seadated.com
140
+ executables: []
141
+
142
+ extensions: []
143
+
144
+ extra_rdoc_files: []
145
+
146
+ files:
147
+ - .gitignore
148
+ - .rvmrc
149
+ - Gemfile
150
+ - README.markdown
151
+ - Rakefile
152
+ - jibeset.gemspec
153
+ - lib/faraday/oauth2.rb
154
+ - lib/jibeset.rb
155
+ - lib/jibeset/api.rb
156
+ - lib/jibeset/client.rb
157
+ - lib/jibeset/client/boats.rb
158
+ - lib/jibeset/client/entries.rb
159
+ - lib/jibeset/client/events.rb
160
+ - lib/jibeset/client/fleets.rb
161
+ - lib/jibeset/client/search.rb
162
+ - lib/jibeset/client/users.rb
163
+ - lib/jibeset/client/utils.rb
164
+ - lib/jibeset/configuration.rb
165
+ - lib/jibeset/connection.rb
166
+ - lib/jibeset/error.rb
167
+ - lib/jibeset/oauth.rb
168
+ - lib/jibeset/request.rb
169
+ - lib/jibeset/version.rb
170
+ - test/jibeset/client/events_test.rb
171
+ - test/jibeset/client/users_test.rb
172
+ - test/jibeset/configuration_test.rb
173
+ - test/jibeset/oauth_test.rb
174
+ - test/test_helper.rb
175
+ has_rdoc: true
176
+ homepage: https://github.com/cnix/ruby-jibeset
177
+ licenses: []
178
+
179
+ post_install_message:
180
+ rdoc_options: []
181
+
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: "0"
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: 1.3.6
196
+ requirements: []
197
+
198
+ rubyforge_project: jibeset
199
+ rubygems_version: 1.6.2
200
+ signing_key:
201
+ specification_version: 3
202
+ summary: Ruby wrapper for the jibeset API
203
+ test_files:
204
+ - test/jibeset/client/events_test.rb
205
+ - test/jibeset/client/users_test.rb
206
+ - test/jibeset/configuration_test.rb
207
+ - test/jibeset/oauth_test.rb
208
+ - test/test_helper.rb