github-api-v3 0.0.1.placeholder → 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.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/README.md +74 -9
- data/github-api-v3.gemspec +4 -1
- data/lib/github.rb +28 -0
- data/lib/github/client.rb +67 -0
- data/lib/github/configuration.rb +15 -0
- data/lib/github/error.rb +11 -0
- data/lib/github/version.rb +1 -1
- data/spec/github/client_spec.rb +53 -0
- data/spec/spec_helper.rb +7 -0
- metadata +42 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39ab5a347837f79c27c8e5623dfb1297ad429ddd
|
4
|
+
data.tar.gz: d4a479ad761d0f9deb795f30bcf23c068ad5b6c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 513c8040828a756849db0066f790ccf35732ccb6839ae14057c1cb3498a509282233a38a5028c204dc2b46f94fcd516052faedc0e59cb0942eb882acd4f7a152
|
7
|
+
data.tar.gz: d6beaa9cec0e17ab082e544a6c3838729c1c2aa4dfb8e2c6e6d32a788135ccb267ec655b978a5d79aee96d7176fddb926433d50c46f491c07596ef8b699e833b
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,24 +1,89 @@
|
|
1
1
|
# GitHub API v3 Wrapper
|
2
2
|
|
3
|
-
|
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
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
As of right now, the library has not reached a version which I consider worth pushing to RubyGems.org. Feel free to clone the repository and build the gem and install it if you wish:
|
8
8
|
|
9
|
-
|
9
|
+
```bash
|
10
|
+
$ git clone https://github.com/caseyscarborough/github && cd github
|
11
|
+
$ gem build github-api-v3.gemspec
|
12
|
+
$ gem install github-api-v3-0.0.1.gem
|
13
|
+
```
|
10
14
|
|
11
|
-
|
15
|
+
## Usage
|
12
16
|
|
13
|
-
|
17
|
+
Add the following line to your gemfile:
|
14
18
|
|
15
|
-
|
19
|
+
```ruby
|
20
|
+
gem 'github-api-v3'
|
21
|
+
```
|
16
22
|
|
17
|
-
|
23
|
+
or install it manually:
|
18
24
|
|
19
|
-
|
25
|
+
```bash
|
26
|
+
$ gem install github-api-v3
|
27
|
+
```
|
28
|
+
|
29
|
+
Then you can proceed to use it in the following manner:
|
30
|
+
|
31
|
+
#### User
|
32
|
+
|
33
|
+
Returns a Hash containing information about a user.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
user = GitHub.user('caseyscarborough')
|
37
|
+
user.login # => "caseyscarborough"
|
38
|
+
user.name # => "Casey Scarborough"
|
39
|
+
user.html_url # => "https://github.com/caseyscarborough"
|
40
|
+
user.following # => 23
|
41
|
+
# etc...
|
42
|
+
```
|
43
|
+
You can find the available attributes [here](http://developer.github.com/v3/users/#get-a-single-user).
|
44
|
+
|
45
|
+
#### Events
|
46
|
+
|
47
|
+
Returns an array of events for a particular user.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
events = GitHub.events('caseyscarborough')
|
51
|
+
events.each { |e| puts e.type }
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Followers
|
55
|
+
|
56
|
+
Returns an array of followers for a user.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
followers = GitHub.followers('caseyscarborough')
|
60
|
+
followers.each { |f| puts f.login }
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Repositories
|
64
|
+
|
65
|
+
Returns an array of repositories that belong to a user.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
repos = GitHub.repos('caseyscarborough')
|
69
|
+
repos.each { |r| puts r.name }
|
70
|
+
```
|
71
|
+
|
72
|
+
### Authenticated Requests
|
73
|
+
|
74
|
+
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).
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
client = GitHub::Client.new(login: 'username', access_token: 'abcdefghijklmnopqrstuvwxyz12345')
|
78
|
+
client.emails # => ["email@example.com", "email2@example.com"]
|
79
|
+
```
|
80
|
+
|
81
|
+
More functionality to come.
|
82
|
+
|
83
|
+
## To Do
|
84
|
+
|
85
|
+
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.
|
20
86
|
|
21
|
-
TODO: Write usage instructions here
|
22
87
|
|
23
88
|
## Contributing
|
24
89
|
|
data/github-api-v3.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['caseyscarborough@gmail.com']
|
11
11
|
spec.description = "A wrapper for GitHub's API v3."
|
12
12
|
spec.summary = "This gem is a wrapper that allows simple interaction with GitHub's API v3."
|
13
|
-
spec.homepage = ''
|
13
|
+
spec.homepage = 'https://github.com/caseyscarborough/github'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
|
25
|
+
spec.add_dependency 'httparty', '0.11.0'
|
23
26
|
end
|
data/lib/github.rb
CHANGED
@@ -1,4 +1,32 @@
|
|
1
|
+
require 'httparty'
|
1
2
|
require 'github/version'
|
3
|
+
require 'github/error'
|
4
|
+
require 'github/configuration'
|
5
|
+
require 'github/client'
|
2
6
|
|
3
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
|
4
32
|
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
|
data/lib/github/error.rb
ADDED
@@ -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
|
data/lib/github/version.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
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
|
+
|
52
|
+
describe 'exceptions' do
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-api-v3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Casey Scarborough
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
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
|
41
69
|
description: A wrapper for GitHub's API v3.
|
42
70
|
email:
|
43
71
|
- caseyscarborough@gmail.com
|
@@ -46,14 +74,20 @@ extensions: []
|
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
76
|
- .gitignore
|
77
|
+
- .rspec
|
49
78
|
- Gemfile
|
50
79
|
- LICENSE
|
51
80
|
- README.md
|
52
81
|
- Rakefile
|
53
82
|
- github-api-v3.gemspec
|
54
83
|
- lib/github.rb
|
84
|
+
- lib/github/client.rb
|
85
|
+
- lib/github/configuration.rb
|
86
|
+
- lib/github/error.rb
|
55
87
|
- lib/github/version.rb
|
56
|
-
|
88
|
+
- spec/github/client_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/caseyscarborough/github
|
57
91
|
licenses:
|
58
92
|
- MIT
|
59
93
|
metadata: {}
|
@@ -68,13 +102,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
102
|
version: '0'
|
69
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
104
|
requirements:
|
71
|
-
- - '
|
105
|
+
- - '>='
|
72
106
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
107
|
+
version: '0'
|
74
108
|
requirements: []
|
75
109
|
rubyforge_project:
|
76
110
|
rubygems_version: 2.0.5
|
77
111
|
signing_key:
|
78
112
|
specification_version: 4
|
79
113
|
summary: This gem is a wrapper that allows simple interaction with GitHub's API v3.
|
80
|
-
test_files:
|
114
|
+
test_files:
|
115
|
+
- spec/github/client_spec.rb
|
116
|
+
- spec/spec_helper.rb
|