github_api_v3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +81 -0
- data/Rakefile +1 -0
- data/github_api_v3.gemspec +26 -0
- data/lib/github_api_v3/client.rb +67 -0
- data/lib/github_api_v3/configuration.rb +15 -0
- data/lib/github_api_v3/error.rb +11 -0
- data/lib/github_api_v3/version.rb +3 -0
- data/lib/github_api_v3.rb +32 -0
- data/spec/github_api_v3/client_spec.rb +51 -0
- data/spec/spec_helper.rb +7 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1484792ee09d3b78a77bbb52789a41c0513c41e
|
4
|
+
data.tar.gz: f4975ee821dbf872a3bd4cc0f6f63dc6190d9eee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91a3f5ac2a6debb3d6dcd7b14098378c55912c9098d5648b899a4ab632ce61a44f701bfa8eb2f563380334265810d71e7cd2d9cc323762a446d6907b9f3a54ae
|
7
|
+
data.tar.gz: a4bfafbe187cbbc114156d23b7ee2a4162abb6d1c01bce6595664dece25a4b4621641a476ea6c6cdbeeb843d4a29e31667145c53aea428e5e5c54ec5abfcf30d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Casey Scarborough
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# GitHub API v3 Wrapper
|
2
|
+
|
3
|
+
This is a simple wrapper for GitHub's v3 API. It is in the EARLY stages of development. Knowing a little about [GitHub's API](http://developer.github.com/) will aid in its use.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
$ gem install github_api_v3
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'github_api_v3'
|
15
|
+
# => true
|
16
|
+
```
|
17
|
+
|
18
|
+
#### User
|
19
|
+
|
20
|
+
Returns a Hash containing information about a user.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
user = GitHub.user('caseyscarborough')
|
24
|
+
user.login # => "caseyscarborough"
|
25
|
+
user.name # => "Casey Scarborough"
|
26
|
+
user.html_url # => "https://github.com/caseyscarborough"
|
27
|
+
user.following # => 23
|
28
|
+
# etc...
|
29
|
+
```
|
30
|
+
You can find the available attributes [here](http://developer.github.com/v3/users/#get-a-single-user).
|
31
|
+
|
32
|
+
#### Events
|
33
|
+
|
34
|
+
Returns an array of events for a particular user.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
events = GitHub.events('caseyscarborough')
|
38
|
+
events.each { |e| puts e.type }
|
39
|
+
```
|
40
|
+
|
41
|
+
#### Followers
|
42
|
+
|
43
|
+
Returns an array of followers for a user.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
followers = GitHub.followers('caseyscarborough')
|
47
|
+
followers.each { |f| puts f.login }
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Repositories
|
51
|
+
|
52
|
+
Returns an array of repositories that belong to a user.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
repos = GitHub.repos('caseyscarborough')
|
56
|
+
repos.each { |r| puts r.name }
|
57
|
+
```
|
58
|
+
|
59
|
+
### Authenticated Requests
|
60
|
+
|
61
|
+
Some methods, such as retrieving private repos or emails, require authentication. To create one of these requests, you'll need to pass in your login and access token. You can create a personal access token on your [account page](https://github.com/settings/applications).
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
client = GitHub::Client.new(login: 'username', access_token: 'abcdefghijklmnopqrstuvwxyz12345')
|
65
|
+
client.emails # => ["email@example.com", "email2@example.com"]
|
66
|
+
```
|
67
|
+
|
68
|
+
More functionality to come.
|
69
|
+
|
70
|
+
## To Do
|
71
|
+
|
72
|
+
The better question is... What's not to do? Any functionality of the API listed at [developer.github.com](http://developer.github.com/) that isn't currently in effect.
|
73
|
+
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'github_api_v3/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'github_api_v3'
|
8
|
+
spec.version = GitHub::VERSION
|
9
|
+
spec.authors = ['Casey Scarborough']
|
10
|
+
spec.email = ['caseyscarborough@gmail.com']
|
11
|
+
spec.description = "A wrapper for GitHub's API v3."
|
12
|
+
spec.summary = "This gem is a wrapper that allows simple interaction with GitHub's API v3."
|
13
|
+
spec.homepage = 'https://github.com/caseyscarborough/github'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
|
25
|
+
spec.add_dependency 'httparty', '0.11.0'
|
26
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module GitHub
|
2
|
+
class Client
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
base_uri Configuration::DEFAULT_ENDPOINT
|
6
|
+
|
7
|
+
attr_reader :login, :access_token
|
8
|
+
|
9
|
+
def initialize(login=nil, access_token=nil)
|
10
|
+
@login = login
|
11
|
+
@access_token = access_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def user(username)
|
15
|
+
get "/users/#{username}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def users
|
19
|
+
get "/users"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get emails for authenticated user
|
23
|
+
def emails
|
24
|
+
get "/user/emails", auth_params
|
25
|
+
end
|
26
|
+
|
27
|
+
def followers(username)
|
28
|
+
get "/users/#{username}/followers"
|
29
|
+
end
|
30
|
+
|
31
|
+
def following(username)
|
32
|
+
get "/users/#{username}/following"
|
33
|
+
end
|
34
|
+
|
35
|
+
def events(username)
|
36
|
+
get "/users/#{username}/events"
|
37
|
+
end
|
38
|
+
|
39
|
+
def repos(username)
|
40
|
+
get "/users/#{username}/repos"
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def get(url, params={})
|
46
|
+
response = self.class.get url, query: params
|
47
|
+
handle_response(response)
|
48
|
+
response.parsed_response
|
49
|
+
end
|
50
|
+
|
51
|
+
def auth_params
|
52
|
+
@login.nil? ? {} : { login: @login, access_token: @access_token }
|
53
|
+
end
|
54
|
+
|
55
|
+
def handle_response(response)
|
56
|
+
case response.code
|
57
|
+
when 401 then raise Unauthorized
|
58
|
+
when 403 then raise RateLimitExceeded
|
59
|
+
when 404 then raise NotFound
|
60
|
+
when 400..500 then raise ClientError
|
61
|
+
when 500..600 then raise ServerError, response.code
|
62
|
+
else
|
63
|
+
response
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GitHub
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
DEFAULT_ENDPOINT = "https://api.github.com".freeze
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ::Hash
|
10
|
+
def method_missing(name)
|
11
|
+
return self[name] if key? name
|
12
|
+
self.each { |k,v| return v if k.to_s.to_sym == name }
|
13
|
+
super.method_missing name
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module GitHub
|
2
|
+
|
3
|
+
class GitHubError < StandardError; end
|
4
|
+
class NotFound < GitHubError; end
|
5
|
+
class Unauthorized < GitHubError; end
|
6
|
+
class Unavailable < GitHubError; end
|
7
|
+
class RateLimitExceeded < GitHubError; end
|
8
|
+
class ServerError < GitHubError; end
|
9
|
+
class ClientError < GitHubError; end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'github_api_v3/version'
|
3
|
+
require 'github_api_v3/error'
|
4
|
+
require 'github_api_v3/configuration'
|
5
|
+
require 'github_api_v3/client'
|
6
|
+
|
7
|
+
module GitHub
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def user(username)
|
12
|
+
Client.new.user(username)
|
13
|
+
end
|
14
|
+
|
15
|
+
def users
|
16
|
+
Client.new.users
|
17
|
+
end
|
18
|
+
|
19
|
+
def followers(username=nil)
|
20
|
+
Client.new.followers(username)
|
21
|
+
end
|
22
|
+
|
23
|
+
def events(username)
|
24
|
+
Client.new.events(username)
|
25
|
+
end
|
26
|
+
|
27
|
+
def repos(username)
|
28
|
+
Client.new.repos(username)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitHub::Client do
|
4
|
+
|
5
|
+
let(:user) { GitHub.user('caseyscarborough') }
|
6
|
+
|
7
|
+
subject { GitHub }
|
8
|
+
|
9
|
+
it { should respond_to :user }
|
10
|
+
it { should respond_to :events }
|
11
|
+
it { should respond_to :followers }
|
12
|
+
it { should respond_to :repos }
|
13
|
+
|
14
|
+
describe 'default attributes' do
|
15
|
+
it 'must include httparty' do
|
16
|
+
GitHub::Client.should include(HTTParty)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'must have base URI set to GitHub API endpoint' do
|
20
|
+
GitHub::Client.base_uri.should eq('https://api.github.com')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'get user data' do
|
25
|
+
it 'should parse the API response from JSON to Hash' do
|
26
|
+
user.should be_instance_of Hash
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should get the correct user info' do
|
30
|
+
user['login'].should eq('caseyscarborough')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'event data' do
|
35
|
+
it 'should return an array of events' do
|
36
|
+
GitHub.events(user['login']).should be_instance_of Array
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'followers' do
|
41
|
+
it 'should return an array of users' do
|
42
|
+
GitHub.followers(user['login']).should be_instance_of Array
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'repositories' do
|
47
|
+
it 'should return an array of repositories' do
|
48
|
+
GitHub.repos(user['login']).should be_instance_of Array
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_api_v3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Casey Scarborough
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.11.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.11.0
|
69
|
+
description: A wrapper for GitHub's API v3.
|
70
|
+
email:
|
71
|
+
- caseyscarborough@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- github_api_v3.gemspec
|
83
|
+
- lib/github_api_v3.rb
|
84
|
+
- lib/github_api_v3/client.rb
|
85
|
+
- lib/github_api_v3/configuration.rb
|
86
|
+
- lib/github_api_v3/error.rb
|
87
|
+
- lib/github_api_v3/version.rb
|
88
|
+
- spec/github_api_v3/client_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/caseyscarborough/github
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.0.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: This gem is a wrapper that allows simple interaction with GitHub's API v3.
|
114
|
+
test_files:
|
115
|
+
- spec/github_api_v3/client_spec.rb
|
116
|
+
- spec/spec_helper.rb
|