octoplex 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +61 -0
- data/Rakefile +12 -0
- data/bin/octoplex_console +14 -0
- data/lib/faraday/response/hashr.rb +21 -0
- data/lib/faraday/response/multi_json.rb +23 -0
- data/lib/faraday/response/raise_octoplex_error.rb +42 -0
- data/lib/octoplex.rb +45 -0
- data/lib/octoplex/client.rb +51 -0
- data/lib/octoplex/client/base.rb +15 -0
- data/lib/octoplex/client/repository.rb +48 -0
- data/lib/octoplex/client/root.rb +37 -0
- data/lib/octoplex/client/user.rb +29 -0
- data/lib/octoplex/connection.rb +74 -0
- data/lib/octoplex/errors.rb +34 -0
- data/lib/octoplex/version.rb +3 -0
- data/octoplex.gemspec +30 -0
- data/spec/lib/octoplex/api/user_spec.rb +23 -0
- data/spec/lib/octoplex/client_spec.rb +57 -0
- data/spec/lib/octoplex/connection_spec.rb +50 -0
- data/spec/lib/octoplex_spec.rb +11 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/custom.rb +1 -0
- metadata +164 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Octoplex
|
2
|
+
|
3
|
+
A lightweight wrapper around Github's v3 API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
gem 'octoplex'
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Octoplex provides both authenticated and unauthenticated usage, however authenticated usage assumes you have
|
14
|
+
acquired an OAuth token for your user from another service, e.g. using Omniauth and Devise.
|
15
|
+
|
16
|
+
If you haven't already done so, register your application with the Github API at [https://github.com/account/applications](https://github.com/account/applications)
|
17
|
+
|
18
|
+
### Authenticated
|
19
|
+
|
20
|
+
Initialise the client with an auth token:
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
Octoplex.client(:token => "OAUTH_TOKEN")
|
24
|
+
```
|
25
|
+
|
26
|
+
Request this users details:
|
27
|
+
|
28
|
+
``` ruby
|
29
|
+
Octoplex.user
|
30
|
+
```
|
31
|
+
|
32
|
+
Request a specific users details:
|
33
|
+
|
34
|
+
``` ruby
|
35
|
+
Octoplex.users('ivanvanderbyl')
|
36
|
+
```
|
37
|
+
|
38
|
+
All client methods are designed to match closely to the [Github v3 API](http://developer.github.com/v3/users/) REST methods.
|
39
|
+
|
40
|
+
Example: Calling `Octoplex.user` will make an API call equivalent to `GET /user`
|
41
|
+
|
42
|
+
Alternatively you can use `Octoplex` as a connection wrapper for the API:
|
43
|
+
|
44
|
+
``` ruby
|
45
|
+
Octoplex.get('/user')
|
46
|
+
Octoplex.get('/user/repos')
|
47
|
+
```
|
48
|
+
|
49
|
+
All requests return a `Hashr` object or `Array` of `Hashr` objects
|
50
|
+
|
51
|
+
All requests on the new v3 API are rate limited, to find out your current usage you can query
|
52
|
+
these two methods after each request:
|
53
|
+
|
54
|
+
``` ruby
|
55
|
+
Octoplex.rate_limit #=> 5000
|
56
|
+
Octoplex.rate_limit_remaining #=> 4999
|
57
|
+
```
|
58
|
+
|
59
|
+
### Language note
|
60
|
+
|
61
|
+
This library is written in International English, so if you're wondering why we've swapped your Zs for S, and added a U to colour – get a dictionary.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'hashr'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response
|
5
|
+
class Hashr < Response::Middleware
|
6
|
+
|
7
|
+
def on_complete(env)
|
8
|
+
begin
|
9
|
+
if env[:body].is_a?(Array)
|
10
|
+
env[:body] = env[:body].map { |o| ::Hashr.new(o) }
|
11
|
+
else
|
12
|
+
env[:body] = ::Hashr.new(env[:body])
|
13
|
+
end
|
14
|
+
rescue
|
15
|
+
env[:body] = env[:body]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'yajl'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
class Response
|
6
|
+
class MultiJson < Response::Middleware
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
super
|
10
|
+
::MultiJson.engine = :yajl
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_complete(env)
|
14
|
+
begin
|
15
|
+
env[:body] = ::MultiJson.decode(env[:body])
|
16
|
+
rescue MultiJson::ParserError
|
17
|
+
env[:body] = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
# @api private
|
5
|
+
module Faraday
|
6
|
+
class Response::RaiseOctoplexError < Response::Middleware
|
7
|
+
def on_complete(response)
|
8
|
+
case response[:status].to_i
|
9
|
+
when 400
|
10
|
+
raise Octoplex::BadRequest, error_message(response)
|
11
|
+
when 401
|
12
|
+
raise Octoplex::Unauthorized, error_message(response)
|
13
|
+
when 403
|
14
|
+
raise Octoplex::Forbidden, error_message(response)
|
15
|
+
when 404
|
16
|
+
raise Octoplex::NotFound, error_message(response)
|
17
|
+
when 406
|
18
|
+
raise Octoplex::NotAcceptable, error_message(response)
|
19
|
+
when 422
|
20
|
+
raise Octoplex::UnprocessableEntity, error_message(response)
|
21
|
+
when 500
|
22
|
+
raise Octoplex::InternalServerError, error_message(response)
|
23
|
+
when 501
|
24
|
+
raise Octoplex::NotImplemented, error_message(response)
|
25
|
+
when 502
|
26
|
+
raise Octoplex::BadGateway, error_message(response)
|
27
|
+
when 503
|
28
|
+
raise Octoplex::ServiceUnavailable, error_message(response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def error_message(response)
|
33
|
+
message = if body = response[:body]
|
34
|
+
body = ::MultiJson.decode(body) if body.is_a? String
|
35
|
+
": #{body[:error] || body[:message] || ''}"
|
36
|
+
else
|
37
|
+
''
|
38
|
+
end
|
39
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/octoplex.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "octoplex/version"
|
2
|
+
require "cgi"
|
3
|
+
require "hashr"
|
4
|
+
require "octoplex/errors"
|
5
|
+
|
6
|
+
module Octoplex
|
7
|
+
autoload :Connection, 'octoplex/connection'
|
8
|
+
autoload :Client, 'octoplex/client'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
# A global instance of the Client class
|
12
|
+
#
|
13
|
+
# Options:
|
14
|
+
# :token - The OAuth token you have retrieved earlier.
|
15
|
+
#
|
16
|
+
def client(options = {})
|
17
|
+
@client ||= Octoplex::Client.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def discard_client!
|
21
|
+
@client = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# @private
|
25
|
+
def log
|
26
|
+
@log ||= begin
|
27
|
+
log = Logger.new($stdout)
|
28
|
+
log.level = Logger::INFO
|
29
|
+
log
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Delegate missing API calls to client, so we can do things like:
|
34
|
+
# Octoplex.users('octocat')
|
35
|
+
# Octoplex.user
|
36
|
+
# Octoplex.repos('octocat')
|
37
|
+
def method_missing(meth, *args, &blk)
|
38
|
+
if client.respond_to?(meth)
|
39
|
+
client.send(meth, *args, &blk)
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Octoplex
|
2
|
+
class Client
|
3
|
+
|
4
|
+
autoload :Root, 'octoplex/client/root'
|
5
|
+
autoload :Base, 'octoplex/client/base'
|
6
|
+
autoload :User, 'octoplex/client/user'
|
7
|
+
autoload :Repository, 'octoplex/client/repository'
|
8
|
+
|
9
|
+
include Octoplex::Client::Root
|
10
|
+
|
11
|
+
attr_accessor :options
|
12
|
+
|
13
|
+
def initialize(options = nil)
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def connection
|
18
|
+
@connection ||= Octoplex::Connection.new(options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# The maximum number of API requests you can do this hour
|
22
|
+
# for this token.
|
23
|
+
def rate_limit
|
24
|
+
connection.rate_limit
|
25
|
+
end
|
26
|
+
|
27
|
+
# The number of API requests you have left this hour.
|
28
|
+
def rate_limit_remaining
|
29
|
+
connection.rate_limit_remaining
|
30
|
+
end
|
31
|
+
|
32
|
+
# API Helper methods
|
33
|
+
|
34
|
+
def get(path)
|
35
|
+
connection.get(path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def post(path, body)
|
39
|
+
connection.post(path, body)
|
40
|
+
end
|
41
|
+
|
42
|
+
def put(path, body)
|
43
|
+
connection.put(path, body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete(path)
|
47
|
+
connection.delete(path)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Octoplex
|
2
|
+
class Client
|
3
|
+
class Repository < Base
|
4
|
+
|
5
|
+
attr_reader :owner
|
6
|
+
|
7
|
+
def initialize(owner, client, data)
|
8
|
+
super(client, data)
|
9
|
+
@owner = owner
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# GET /repos/:user/:repo
|
15
|
+
|
16
|
+
# GET /repos/:user/:repo/contributors
|
17
|
+
def contributors
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /repos/:user/:repo/languages
|
22
|
+
def languages
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET /repos/:user/:repo/teams
|
27
|
+
def teams
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# GET /repos/:user/:repo/branches
|
32
|
+
def branches
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# Commits:
|
37
|
+
# GET /repos/:user/:repo/commits
|
38
|
+
# GET /repos/:user/:repo/commits/:sha
|
39
|
+
# GET /repos/:user/:repo/comments
|
40
|
+
# GET /repos/:user/:repo/commits/:sha/comments
|
41
|
+
# POST /repos/:user/:repo/commits/:sha/comments
|
42
|
+
# GET /repos/:user/:repo/comments/:id
|
43
|
+
# PATCH /repos/:user/:repo/comments/:id
|
44
|
+
# GET /repos/:user/:repo/compare/:base...:head
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Octoplex
|
2
|
+
class Client
|
3
|
+
module Root
|
4
|
+
|
5
|
+
# GET /users/:user
|
6
|
+
# GET /users/:user/repos
|
7
|
+
def users(login)
|
8
|
+
(@users ||= {})[login] ||= Octoplex::API::User.new(self, get("/users/#{login}"))
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /user
|
12
|
+
# GET /user/repos
|
13
|
+
def user
|
14
|
+
@user ||= Octoplex::API::User.current
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET /orgs/:org/repos
|
18
|
+
def orgs(login)
|
19
|
+
Octoplex::API::Organisation.find(login)
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :organisations, :orgs
|
23
|
+
alias_method :organizations, :orgs
|
24
|
+
|
25
|
+
# GET /repos/:user/:repo
|
26
|
+
# GET /repos/:user/:repo/contributors
|
27
|
+
# GET /repos/:user/:repo/languages
|
28
|
+
# GET /repos/:user/:repo/teams
|
29
|
+
# GET /repos/:user/:repo/branches
|
30
|
+
|
31
|
+
def repos(user, repo)
|
32
|
+
(@repos ||= {})[user] ||= Octoplex::API::Repository.new(user, self, get("/repos/#{user}"))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Octoplex
|
2
|
+
class Client
|
3
|
+
class Users < Base
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# class << self
|
8
|
+
# def find(client, login)
|
9
|
+
# new(client.get("/users/#{login}"))
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# def current(client)
|
13
|
+
# new(client.get("/user"))
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
|
17
|
+
# GET /users/:user/[repos]
|
18
|
+
# def repos
|
19
|
+
# Octoplex::API::Repository.all
|
20
|
+
# # get("/user/#{login}/repos")
|
21
|
+
# end
|
22
|
+
|
23
|
+
def repos
|
24
|
+
Octoplex::API::Repository.new(login, self, get("/users/repos"))
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday/response/multi_json"
|
3
|
+
require "faraday/response/hashr"
|
4
|
+
require "faraday/response/raise_octoplex_error"
|
5
|
+
|
6
|
+
module Octoplex
|
7
|
+
class Connection
|
8
|
+
|
9
|
+
attr_reader :conn, :options, :token, :rate_limit, :rate_limit_remaining
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
options ||= {}
|
13
|
+
|
14
|
+
@options = {
|
15
|
+
:token => nil,
|
16
|
+
:per_page => 100
|
17
|
+
}.update(options)
|
18
|
+
|
19
|
+
@token = options.delete(:token)
|
20
|
+
@rate_limit = @rate_limit_remaining = 0
|
21
|
+
setup
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@conn = Faraday.new(:url => 'https://api.github.com') do |builder|
|
26
|
+
builder.use Faraday::Request::JSON
|
27
|
+
builder.use Faraday::Response::Logger
|
28
|
+
builder.use Faraday::Adapter::NetHttp
|
29
|
+
builder.use Faraday::Response::Hashr
|
30
|
+
builder.use Faraday::Response::RaiseOctoplexError
|
31
|
+
builder.use Faraday::Response::MultiJson
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def authentication_param
|
36
|
+
{:access_token => token}
|
37
|
+
end
|
38
|
+
|
39
|
+
def get(path)
|
40
|
+
request(path, :get)
|
41
|
+
end
|
42
|
+
|
43
|
+
def post(path, body)
|
44
|
+
request(path, :post, body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def put(path, body)
|
48
|
+
request(path, :put, body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete(path)
|
52
|
+
request(path, :delete)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def request(path, method = :get, body = nil)
|
58
|
+
response = conn.send(method) do |req|
|
59
|
+
req.url(path, options)
|
60
|
+
req.body = body unless body.nil?
|
61
|
+
req.params['access_token'] = self.token if self.token.is_a?(String)
|
62
|
+
end
|
63
|
+
|
64
|
+
if response.env[:response_headers].has_key?('x-ratelimit-limit')
|
65
|
+
@rate_limit = response.env[:response_headers]['x-ratelimit-limit'].to_i
|
66
|
+
@rate_limit_remaining = response.env[:response_headers]['x-ratelimit-remaining'].to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
response.body
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Octoplex
|
2
|
+
# Custom error class for rescuing from all GitHub errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when GitHub returns a 400 HTTP status code
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when GitHub returns a 401 HTTP status code
|
9
|
+
class Unauthorized < Error; end
|
10
|
+
|
11
|
+
# Raised when GitHub returns a 403 HTTP status code
|
12
|
+
class Forbidden < Error; end
|
13
|
+
|
14
|
+
# Raised when GitHub returns a 404 HTTP status code
|
15
|
+
class NotFound < Error; end
|
16
|
+
|
17
|
+
# Raised when GitHub returns a 406 HTTP status code
|
18
|
+
class NotAcceptable < Error; end
|
19
|
+
|
20
|
+
# Raised when GitHub returns a 422 HTTP status code
|
21
|
+
class UnprocessableEntity < Error; end
|
22
|
+
|
23
|
+
# Raised when GitHub returns a 500 HTTP status code
|
24
|
+
class InternalServerError < Error; end
|
25
|
+
|
26
|
+
# Raised when GitHub returns a 501 HTTP status code
|
27
|
+
class NotImplemented < Error; end
|
28
|
+
|
29
|
+
# Raised when GitHub returns a 502 HTTP status code
|
30
|
+
class BadGateway < Error; end
|
31
|
+
|
32
|
+
# Raised when GitHub returns a 503 HTTP status code
|
33
|
+
class ServiceUnavailable < Error; end
|
34
|
+
end
|
data/octoplex.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "octoplex/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "octoplex"
|
7
|
+
s.version = Octoplex::VERSION
|
8
|
+
s.authors = ["Ivan Vanderbyl"]
|
9
|
+
s.email = ["ivanvanderbyl@me.com"]
|
10
|
+
s.homepage = "http://testpilot.me/testpilot/octoplex"
|
11
|
+
s.summary = %q{A lightweight wrapper around the Github v3 API}
|
12
|
+
s.description = %q{A lightweight wrapper around the Github v3 API}
|
13
|
+
|
14
|
+
s.rubyforge_project = "octoplex"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "mocha"
|
23
|
+
s.add_development_dependency "awesome_print"
|
24
|
+
|
25
|
+
s.add_runtime_dependency "faraday"
|
26
|
+
s.add_runtime_dependency "multi_json"
|
27
|
+
s.add_runtime_dependency "yajl-ruby"
|
28
|
+
s.add_runtime_dependency "hashr"
|
29
|
+
s.add_runtime_dependency "link_header", "0.0.5"
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Octoplex::API::User do
|
4
|
+
describe "repos" do
|
5
|
+
it "should make API call to /user/repos" do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return an array of Repository objects" do
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "followers" do
|
15
|
+
it "should make an API call to /user/followers" do
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return an array of User objects" do
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
require "octoplex/connection"
|
4
|
+
|
5
|
+
describe Octoplex::Client do
|
6
|
+
before(:each) do
|
7
|
+
Octoplex.discard_client!
|
8
|
+
c = Faraday::Adapter::Test::Stubs.new
|
9
|
+
|
10
|
+
test = Faraday.new do |builder|
|
11
|
+
builder.adapter :test, c do |stub|
|
12
|
+
stub.get('/user/keys') {[ 200, {'x-ratelimit-remaining' => '4999', 'x-ratelimit-limit' => '5000'}, "{}" ]}
|
13
|
+
stub.post('/user/keys/123') {[ 200, {}, "{}" ]}
|
14
|
+
end
|
15
|
+
|
16
|
+
builder.use Faraday::Response::MultiJson
|
17
|
+
end
|
18
|
+
Octoplex::Connection.any_instance.stubs(:setup)
|
19
|
+
Octoplex::Connection.any_instance.stubs(:conn).returns(test)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "rate limits" do
|
23
|
+
it "should be updated after each request" do
|
24
|
+
Octoplex.client.rate_limit.should == 0
|
25
|
+
Octoplex.client.connection.get('/user/keys')
|
26
|
+
Octoplex.client.rate_limit.should == 5000
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should update remaining limit after request" do
|
30
|
+
Octoplex.client.rate_limit_remaining.should == 0
|
31
|
+
Octoplex.client.connection.get('/user/keys')
|
32
|
+
Octoplex.client.rate_limit_remaining.should == 4999
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "API methods" do
|
37
|
+
it "should delegate #get to connection" do
|
38
|
+
Octoplex::Connection.any_instance.expects(:get).once.with('/user/keys')
|
39
|
+
Octoplex.client.get('/user/keys')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should delegate #post to connection" do
|
43
|
+
Octoplex::Connection.any_instance.expects(:post).once.with('/user/keys', {:key => '1233'})
|
44
|
+
Octoplex.client.post('/user/keys', {:key => '1233'})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should delegate #put to connection" do
|
48
|
+
Octoplex::Connection.any_instance.expects(:put).once.with('/user/keys', {:key => '1233'})
|
49
|
+
Octoplex.client.put('/user/keys', {:key => '1233'})
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should delegate #delete to connection" do
|
53
|
+
Octoplex::Connection.any_instance.expects(:delete).once.with('/user/keys')
|
54
|
+
Octoplex.client.delete('/user/keys')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
describe Octoplex::Connection do
|
4
|
+
let(:user_key) {
|
5
|
+
{
|
6
|
+
:key => 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2',
|
7
|
+
:url => "https://api.github.com/user/keys/123",
|
8
|
+
:title => "SSH Key",
|
9
|
+
:id => 123
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:user_keys_payload) {
|
14
|
+
keys = [
|
15
|
+
user_key
|
16
|
+
]
|
17
|
+
|
18
|
+
JSON.dump(keys)
|
19
|
+
}
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
c = Faraday::Adapter::Test::Stubs.new
|
23
|
+
|
24
|
+
test = Faraday.new do |builder|
|
25
|
+
builder.adapter :test, c do |stub|
|
26
|
+
stub.get('/user/keys') {[ 200, {}, user_keys_payload ]}
|
27
|
+
stub.post('/user/keys/123') {[ 200, {}, JSON.dump(user_key) ]}
|
28
|
+
end
|
29
|
+
|
30
|
+
builder.use Faraday::Response::MultiJson
|
31
|
+
end
|
32
|
+
Octoplex::Connection.any_instance.stubs(:setup)
|
33
|
+
Octoplex::Connection.any_instance.stubs(:conn).returns(test)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should handle a GET request to github and parse response" do
|
37
|
+
conn = Octoplex::Connection.new
|
38
|
+
conn.get('/user/keys').should be_a Array
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should handle a POST request to github and parse response" do
|
42
|
+
conn = Octoplex::Connection.new
|
43
|
+
conn.post('/user/keys/123', {:key => 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2'}).values.should == user_key.values
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return accept token as first argument" do
|
47
|
+
conn = Octoplex::Connection.new('1234')
|
48
|
+
conn.token.should == '1234'
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Octoplex do
|
4
|
+
describe "#connection" do
|
5
|
+
it "should store a cached instance of Client" do
|
6
|
+
Octoplex.instance_variable_get("@client").should be_nil
|
7
|
+
Octoplex.client.should be_a Octoplex::Client
|
8
|
+
Octoplex.instance_variable_get("@client").should be_a Octoplex::Client
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
alias :doing :lambda
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octoplex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Vanderbyl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70317821260920 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70317821260920
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
requirement: &70317821254640 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70317821254640
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: awesome_print
|
38
|
+
requirement: &70317821248040 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70317821248040
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: faraday
|
49
|
+
requirement: &70317821244280 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70317821244280
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: multi_json
|
60
|
+
requirement: &70317817138400 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70317817138400
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yajl-ruby
|
71
|
+
requirement: &70317817135720 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70317817135720
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: hashr
|
82
|
+
requirement: &70317817133640 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70317817133640
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: link_header
|
93
|
+
requirement: &70317817129820 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - =
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.0.5
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70317817129820
|
102
|
+
description: A lightweight wrapper around the Github v3 API
|
103
|
+
email:
|
104
|
+
- ivanvanderbyl@me.com
|
105
|
+
executables:
|
106
|
+
- octoplex_console
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- .gitignore
|
111
|
+
- Gemfile
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/octoplex_console
|
115
|
+
- lib/faraday/response/hashr.rb
|
116
|
+
- lib/faraday/response/multi_json.rb
|
117
|
+
- lib/faraday/response/raise_octoplex_error.rb
|
118
|
+
- lib/octoplex.rb
|
119
|
+
- lib/octoplex/client.rb
|
120
|
+
- lib/octoplex/client/base.rb
|
121
|
+
- lib/octoplex/client/repository.rb
|
122
|
+
- lib/octoplex/client/root.rb
|
123
|
+
- lib/octoplex/client/user.rb
|
124
|
+
- lib/octoplex/connection.rb
|
125
|
+
- lib/octoplex/errors.rb
|
126
|
+
- lib/octoplex/version.rb
|
127
|
+
- octoplex.gemspec
|
128
|
+
- spec/lib/octoplex/api/user_spec.rb
|
129
|
+
- spec/lib/octoplex/client_spec.rb
|
130
|
+
- spec/lib/octoplex/connection_spec.rb
|
131
|
+
- spec/lib/octoplex_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/support/custom.rb
|
134
|
+
homepage: http://testpilot.me/testpilot/octoplex
|
135
|
+
licenses: []
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project: octoplex
|
154
|
+
rubygems_version: 1.8.10
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: A lightweight wrapper around the Github v3 API
|
158
|
+
test_files:
|
159
|
+
- spec/lib/octoplex/api/user_spec.rb
|
160
|
+
- spec/lib/octoplex/client_spec.rb
|
161
|
+
- spec/lib/octoplex/connection_spec.rb
|
162
|
+
- spec/lib/octoplex_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
- spec/support/custom.rb
|