githubris 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -2
- data/Gemfile +6 -3
- data/README.md +14 -0
- data/Rakefile +5 -11
- data/githubris.gemspec +2 -0
- data/lib/githubris.rb +18 -8
- data/lib/githubris/api.rb +89 -11
- data/lib/githubris/api/gist.rb +34 -15
- data/lib/githubris/api/http.rb +12 -0
- data/lib/githubris/api/user.rb +10 -4
- data/lib/githubris/base.rb +80 -0
- data/lib/githubris/comment.rb +1 -6
- data/lib/githubris/error.rb +5 -0
- data/lib/githubris/gist.rb +15 -60
- data/lib/githubris/gist/file.rb +1 -8
- data/lib/githubris/oauth.rb +36 -0
- data/lib/githubris/publicity.rb +13 -0
- data/lib/githubris/user.rb +13 -28
- data/lib/githubris/version.rb +1 -1
- data/spec/githubris/api/gist_spec.rb +8 -41
- data/spec/githubris/api/user_spec.rb +17 -2
- data/spec/githubris/api_spec.rb +99 -0
- data/spec/githubris/base_spec.rb +77 -0
- data/spec/githubris/gist_spec.rb +21 -76
- data/spec/githubris/oauth_spec.rb +71 -0
- data/spec/githubris/publicity_spec.rb +22 -0
- data/spec/githubris/user_spec.rb +50 -13
- data/spec/githubris_spec.rb +34 -40
- data/spec/spec_helper.rb +9 -6
- data/spec/support/fixtures.rb +115 -99
- data/spec/support/fixtures/vcr_cassettes/Githubris/_find_gist.yml +44 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris/_find_user.yml +40 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris/_public_gists.yml +55 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API/_authenticated_/when_authenticated_with_bad_credentials.yml +40 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API/_authenticated_/when_authenticated_with_good_credentials.yml +42 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API/_authenticated_/when_there_are_no_credentials.yml +42 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API_Gist/_get_gist.yml +44 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API_Gist/_get_public_gists.yml +107 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API_Gist/_get_user_gists.yml +43 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API_User/_get_authenticated_user/without_credentials.yml +42 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_API_User/_get_user.yml +40 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_Gist/_save.yml +42 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_Gist/any_gist.yml +44 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_Gist/given_a_gist_full_of_data.yml +44 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_Gist/on_a_gist_with_an_id.yml +44 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_Gist/on_a_gist_with_an_id/_reload.yml +44 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_User/_gists.yml +43 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_User/_reload.yml +40 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_User/_reload/on_a_user_with_a_login.yml +40 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_User/_reload/on_a_user_without_a_login.yml +40 -0
- data/spec/support/fixtures/vcr_cassettes/Githubris_User/_starred_gists/on_an_authenticated_user.yml +82 -0
- data/spec/support/vcr.rb +6 -0
- metadata +57 -21
- data/features/get_a_gist.feature +0 -13
- data/features/get_a_user.feature +0 -8
- data/features/list_of_public_gists.feature +0 -12
- data/features/list_of_users_public_gists.feature +0 -13
- data/features/step_definitions/general_steps.rb +0 -32
- data/features/support/env.rb +0 -6
- data/features/support/fakeweb_responses.rb +0 -12
- data/features/support/fixtures.rb +0 -47
- data/lib/githubris/builder.rb +0 -28
- data/spec/githubris/builder_spec.rb +0 -28
- data/spec/support/custom_matchers.rb +0 -27
- data/spec/support/fakeweb_responses.rb +0 -12
- data/spec/support/gist.json +0 -335
- data/spec/support/public_gists_page_1.json +0 -884
- data/spec/support/public_gists_page_2.json +0 -898
- data/spec/support/user.json +0 -14
- data/spec/support/user_public_gists.json +0 -65
data/.travis.yml
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
language: ruby
|
2
|
-
script: 'rake
|
2
|
+
script: 'rake ci --trace'
|
3
3
|
rvm:
|
4
4
|
- 1.9.2
|
5
5
|
- 1.9.3
|
6
|
-
-
|
6
|
+
- rbx-19mode
|
7
7
|
- ruby-head
|
8
8
|
- jruby-head
|
9
|
+
# Breaks on the JSON stuff
|
10
|
+
# - 1.8.7
|
11
|
+
# - jruby-18mode
|
12
|
+
# - jruby-19mode
|
13
|
+
# - rbx-18mode
|
14
|
+
# - ree
|
data/Gemfile
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
group :development, :test do
|
4
|
-
gem 'cucumber'
|
5
4
|
gem 'rspec', '~> 2.8.0'
|
6
5
|
gem 'rspec-spies'
|
7
|
-
gem '
|
6
|
+
gem 'pry'
|
7
|
+
|
8
8
|
gem 'simplecov'
|
9
9
|
gem 'flog'
|
10
10
|
gem 'flay'
|
11
|
+
|
12
|
+
gem 'fakeweb'
|
13
|
+
gem 'vcr'
|
11
14
|
end
|
12
15
|
|
13
|
-
gem 'jruby-openssl', platform
|
16
|
+
gem 'jruby-openssl', :platform => 'jruby'
|
14
17
|
|
15
18
|
gem 'rake'
|
16
19
|
gemspec
|
data/README.md
CHANGED
@@ -4,6 +4,10 @@ This is the best github API wrapper ever.
|
|
4
4
|
|
5
5
|
##Contributing
|
6
6
|
|
7
|
+
Before you contribute you need to:
|
8
|
+
|
9
|
+
1. `bundle install`
|
10
|
+
|
7
11
|
There are a couple of ways that you can contribute to Githubris. For example:
|
8
12
|
|
9
13
|
1. You can take a bug and verify the replication steps
|
@@ -16,3 +20,13 @@ There are a couple of ways that you can contribute to Githubris. For example:
|
|
16
20
|
5. You can open pull requests to pull in your contributions
|
17
21
|
6. You can correct typos or grammar issues.
|
18
22
|
7. You can help in __any__ way you want!
|
23
|
+
|
24
|
+
LICENSE
|
25
|
+
|
26
|
+
Copyright (C) 2012 Isaac Sanders
|
27
|
+
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
29
|
+
|
30
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
31
|
+
|
32
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
-
require 'cucumber/rake/task'
|
4
3
|
require 'flay_task'
|
5
4
|
require 'flog_task'
|
6
5
|
|
@@ -8,14 +7,8 @@ RSpec::Core::RakeTask.new :spec do |t|
|
|
8
7
|
t.rspec_opts = '--color --format=documentation'
|
9
8
|
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
t.cucumber_opts = '--tags @wip --tags ~@backlog'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
Cucumber::Rake::Task.new :features do |t|
|
18
|
-
t.cucumber_opts = '--tags ~@wip --tags ~@backlog'
|
10
|
+
task :cov do
|
11
|
+
ENV['COVERAGE'] = 'true'
|
19
12
|
end
|
20
13
|
|
21
14
|
FLAY_FLOG_OPTS_BLOCK = lambda do |t|
|
@@ -26,5 +19,6 @@ end
|
|
26
19
|
FlayTask.new &FLAY_FLOG_OPTS_BLOCK
|
27
20
|
FlogTask.new &FLAY_FLOG_OPTS_BLOCK
|
28
21
|
|
29
|
-
task :
|
30
|
-
task :
|
22
|
+
task :ci => [:spec]
|
23
|
+
task :all => [:cov, :spec, :flay, :flog]
|
24
|
+
task :default => [:cov, :spec]
|
data/githubris.gemspec
CHANGED
data/lib/githubris.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
$:.push File.expand_path("../../config", __FILE__)
|
2
|
-
|
3
1
|
class Githubris
|
4
2
|
autoload :API, 'githubris/api'
|
3
|
+
autoload :Base, 'githubris/base'
|
5
4
|
autoload :Blob, 'githubris/blob'
|
6
|
-
autoload :Builder, 'githubris/builder'
|
7
5
|
autoload :Comment, 'githubris/comment'
|
8
6
|
autoload :Commit, 'githubris/commit'
|
7
|
+
autoload :Error, 'githubris/error'
|
9
8
|
autoload :Event, 'githubris/event'
|
10
9
|
autoload :Gist, 'githubris/gist'
|
11
10
|
autoload :Issue, 'githubris/issue'
|
11
|
+
autoload :OAuth, 'githubris/oauth'
|
12
12
|
autoload :Organization, 'githubris/organization'
|
13
|
+
autoload :Publicity, 'githubris/publicity'
|
13
14
|
autoload :PullRequest, 'githubris/pull_request'
|
14
15
|
autoload :Reference, 'githubris/reference'
|
15
16
|
autoload :Repository, 'githubris/repository'
|
@@ -18,15 +19,24 @@ class Githubris
|
|
18
19
|
autoload :User, 'githubris/user'
|
19
20
|
autoload :Version, 'githubris/version'
|
20
21
|
|
21
|
-
attr_reader :authenticated_user
|
22
|
-
|
23
22
|
def initialize
|
24
23
|
@api = Githubris::API.new
|
25
24
|
end
|
26
25
|
|
27
|
-
def
|
28
|
-
@api.
|
29
|
-
|
26
|
+
def basic_auth(login, password)
|
27
|
+
@api.basic_auth login, password
|
28
|
+
end
|
29
|
+
|
30
|
+
def oauth(client_id, client_secret)
|
31
|
+
@api.oauth client_id, client_secret
|
32
|
+
end
|
33
|
+
|
34
|
+
def authenticated_user
|
35
|
+
@api.get_authenticated_user
|
36
|
+
end
|
37
|
+
|
38
|
+
def authenticated?
|
39
|
+
@api.authenticated?
|
30
40
|
end
|
31
41
|
|
32
42
|
def find_user(login)
|
data/lib/githubris/api.rb
CHANGED
@@ -1,22 +1,100 @@
|
|
1
|
-
require '
|
1
|
+
require 'addressable/uri'
|
2
2
|
|
3
3
|
class Githubris::API
|
4
|
-
include HTTParty
|
5
4
|
|
6
|
-
|
5
|
+
autoload :HTTP, 'githubris/api/http'
|
6
|
+
include Githubris::API::HTTP
|
7
|
+
autoload :Gist, 'githubris/api/gist'
|
7
8
|
include Githubris::API::Gist
|
8
|
-
|
9
|
-
require_relative 'api/user'
|
9
|
+
autoload :User, 'githubris/api/user'
|
10
10
|
include Githubris::API::User
|
11
11
|
|
12
|
-
base_uri 'https://api.github.com'
|
13
|
-
format :json
|
14
|
-
|
15
12
|
def initialize
|
16
|
-
@
|
13
|
+
@target = Addressable::URI.new default_uri_options
|
14
|
+
@options = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_uri_options
|
18
|
+
{
|
19
|
+
:scheme => 'https',
|
20
|
+
:host => 'api.github.com',
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def basic_auth login, password
|
25
|
+
@options[:basic_auth] = {
|
26
|
+
:username => login,
|
27
|
+
:password => password
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def oauth(client_id, client_secret)
|
32
|
+
oauth = Githubris::OAuth.new client_id, client_secret
|
33
|
+
end
|
34
|
+
|
35
|
+
def authenticated?
|
36
|
+
get_authenticated_user
|
37
|
+
rescue Githubris::Error::RequiresAuthentication, Githubris::Error::BadCredentials
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_data_from(path, options={})
|
42
|
+
this = self
|
43
|
+
data = get(path, options)
|
44
|
+
data = MultiJson.decode(data, :symbolize_keys => true)
|
45
|
+
raise build_error data if error_data?(data)
|
46
|
+
|
47
|
+
embed_self_in data
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_error data
|
51
|
+
words = data[:message].split(' ')
|
52
|
+
error_class_name = words.map {|word| word.capitalize}.join
|
53
|
+
Githubris::Error.const_get(error_class_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get(path, options={})
|
57
|
+
@target.path = path
|
58
|
+
@target.query_values = options
|
59
|
+
MultiJson.encode(_get(@target.to_s))
|
60
|
+
end
|
61
|
+
|
62
|
+
def error_data?(data)
|
63
|
+
data.is_a?(Hash) and data[:message]
|
64
|
+
end
|
65
|
+
|
66
|
+
def post_oauth_access_token(params)
|
67
|
+
@target.query ||= ''
|
68
|
+
@target.query += _post(oauth_access_token_url, :query => params)
|
69
|
+
@target.query_values['access_token']
|
70
|
+
end
|
71
|
+
|
72
|
+
def post_data_to(path, params)
|
73
|
+
data = post(path, MultiJson.encode(params))
|
74
|
+
data = MultiJson.decode(data, :symbolize_keys => true) if data.is_a? String
|
75
|
+
raise build_error data if error_data?(data)
|
76
|
+
|
77
|
+
embed_self_in data
|
78
|
+
end
|
79
|
+
|
80
|
+
def embed_self_in(data)
|
81
|
+
this = self
|
82
|
+
if data.is_a? Array
|
83
|
+
data.each {|data_el| data_el[:_api] = this }
|
84
|
+
else
|
85
|
+
data[:_api] = this
|
86
|
+
end
|
87
|
+
|
88
|
+
data
|
89
|
+
end
|
90
|
+
|
91
|
+
def post(path, params)
|
92
|
+
@target.path = path
|
93
|
+
@options[:body] = params
|
94
|
+
MultiJson.encode(_post(@target.to_s))
|
17
95
|
end
|
18
96
|
|
19
|
-
def
|
20
|
-
|
97
|
+
def oauth_access_token_url
|
98
|
+
'https://github.com/login/oauth/access_token'
|
21
99
|
end
|
22
100
|
end
|
data/lib/githubris/api/gist.rb
CHANGED
@@ -1,38 +1,57 @@
|
|
1
1
|
module Githubris::API::Gist
|
2
|
-
PUBLIC_GISTS_PATH = '/gists/public'
|
3
2
|
|
4
|
-
def
|
5
|
-
|
3
|
+
def get_user_gists(login, options={})
|
4
|
+
get_gists_from(user_gists_path(login), options)
|
6
5
|
end
|
7
6
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
7
|
+
def get_user_starred_gists(options={})
|
8
|
+
get_gists_from(user_starred_gists_path, options)
|
9
|
+
end
|
11
10
|
|
12
|
-
|
11
|
+
def get_public_gists(options={})
|
12
|
+
get_gists_from(public_gists_path, options)
|
13
13
|
end
|
14
14
|
|
15
15
|
def get_gist(id)
|
16
|
-
|
16
|
+
get_gist_from(gist_path(id))
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def post_gist(params)
|
20
|
+
post_gist_to(gists_path, params)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
private
|
24
|
+
def get_gists_from(path, options={})
|
25
|
+
get_data_from(path, options).map do |gist_data|
|
26
|
+
Githubris::Gist.new gist_data
|
27
|
+
end
|
25
28
|
end
|
26
29
|
|
27
|
-
def
|
28
|
-
|
30
|
+
def get_gist_from(path)
|
31
|
+
Githubris::Gist.new get_data_from(path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def post_gist_to(path, params)
|
35
|
+
Githubris::Gist.new post_data_to(path, params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def public_gists_path
|
39
|
+
"#{gists_path}/public"
|
29
40
|
end
|
30
41
|
|
31
42
|
def user_gists_path(login)
|
32
43
|
"/users/#{login}/gists"
|
33
44
|
end
|
34
45
|
|
46
|
+
def user_starred_gists_path
|
47
|
+
"#{gists_path}/starred"
|
48
|
+
end
|
49
|
+
|
35
50
|
def gist_path(id)
|
36
|
-
"
|
51
|
+
"#{gists_path}/#{id}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def gists_path
|
55
|
+
'/gists'
|
37
56
|
end
|
38
57
|
end
|
data/lib/githubris/api/user.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
module Githubris::API::User
|
2
|
-
USERS_PATH = '/users'
|
3
2
|
|
4
3
|
def get_user(login)
|
5
|
-
|
6
|
-
|
4
|
+
Githubris::User.new get_data_from(user_path(login))
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_authenticated_user
|
8
|
+
Githubris::User.new get_data_from(authenticated_user_path)
|
7
9
|
end
|
8
10
|
|
9
11
|
private
|
10
12
|
def user_path(login)
|
11
|
-
"
|
13
|
+
"/users/#{login}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def authenticated_user_path
|
17
|
+
'/user'
|
12
18
|
end
|
13
19
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class Githubris::Base
|
2
|
+
def initialize attributes={}
|
3
|
+
@api = attributes.delete(:_api) || Githubris::API.new
|
4
|
+
@attributes = attributes
|
5
|
+
end
|
6
|
+
|
7
|
+
def ==(other)
|
8
|
+
@attributes == other.instance_variable_get(:@attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def swap_attributes(other)
|
12
|
+
instance_variable_set(:@attributes,
|
13
|
+
other.instance_variable_get(:@attributes))
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def accessible_attribute(*attr_names)
|
21
|
+
attr_names.each do |name|
|
22
|
+
class_eval accessible_methods_called(name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def accessible_methods_called(name)
|
27
|
+
"""
|
28
|
+
def #{name}
|
29
|
+
@attributes[:#{name}]
|
30
|
+
end
|
31
|
+
|
32
|
+
def #{name}=(#{name})
|
33
|
+
@attributes[:#{name}] = #{name}
|
34
|
+
end
|
35
|
+
"""
|
36
|
+
end
|
37
|
+
|
38
|
+
def uri_attribute(*attr_names)
|
39
|
+
attr_names.each do |name|
|
40
|
+
class_eval uri_method_called(name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def uri_method_called(name)
|
45
|
+
"""
|
46
|
+
def #{name}
|
47
|
+
URI.parse @attributes[:#{name}]
|
48
|
+
end
|
49
|
+
"""
|
50
|
+
end
|
51
|
+
|
52
|
+
def datetime_attribute(*attr_names)
|
53
|
+
attr_names.each do |name|
|
54
|
+
class_eval datetime_method_called(name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def datetime_method_called(name)
|
59
|
+
"""
|
60
|
+
def #{name}
|
61
|
+
DateTime.parse @attributes[:#{name}]
|
62
|
+
end
|
63
|
+
"""
|
64
|
+
end
|
65
|
+
|
66
|
+
def readable_attribute(*attr_names)
|
67
|
+
attr_names.each do |name|
|
68
|
+
class_eval readable_method_called(name)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def readable_method_called(name)
|
73
|
+
"""
|
74
|
+
def #{name}
|
75
|
+
@attributes[:#{name}]
|
76
|
+
end
|
77
|
+
"""
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|