githubris 0.0.1 → 0.0.2
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 +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +5 -2
- data/README.md +16 -1
- data/Rakefile +8 -3
- data/features/list_of_public_gists.feature +12 -0
- data/features/list_of_users_public_gists.feature +14 -0
- data/features/step_definitions/general_steps.rb +20 -0
- data/features/step_definitions/public_gist_steps.rb +0 -0
- data/features/support/env.rb +6 -0
- data/features/support/fakeweb_responses.rb +6 -0
- data/features/support/fixtures.rb +11 -0
- data/features/support/public_gists_page_1.json +884 -0
- data/features/support/public_gists_page_2.json +898 -0
- data/githubris.gemspec +0 -1
- data/lib/githubris/api.rb +38 -20
- data/lib/githubris/builder.rb +31 -22
- data/lib/githubris/comment.rb +1 -1
- data/lib/githubris/gist/file.rb +1 -1
- data/lib/githubris/gist.rb +1 -10
- data/lib/githubris/issue.rb +1 -1
- data/lib/githubris/organization.rb +1 -1
- data/lib/githubris/repository.rb +1 -1
- data/lib/githubris/user.rb +6 -7
- data/lib/githubris/version.rb +2 -2
- data/lib/githubris.rb +17 -16
- data/spec/githubris/api_spec.rb +18 -20
- data/spec/githubris/builder_spec.rb +30 -14
- data/spec/githubris/gist_spec.rb +0 -30
- data/spec/githubris_spec.rb +48 -0
- data/spec/spec_helper.rb +8 -1
- data/spec/support/fakeweb_responses.rb +2 -57
- data/spec/support/fixtures.rb +1 -1
- data/spec/support/public_gists_page_1.json +884 -0
- data/spec/support/public_gists_page_2.json +898 -0
- metadata +17 -8
- data/config/base.yml +0 -1
- data/config/gists.yml +0 -13
- data/config.yml +0 -1
- data/lib/githubris/config.rb +0 -13
data/githubris.gemspec
CHANGED
data/lib/githubris/api.rb
CHANGED
@@ -1,26 +1,44 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
class Githubris::API
|
4
|
+
include HTTParty
|
5
|
+
base_uri 'https://api.github.com'
|
6
|
+
format :json
|
7
|
+
|
8
|
+
GISTS_PER_PAGE = 30
|
9
|
+
PUBLIC_GISTS_PATH = '/gists/public'
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@builder = Githubris::Builder.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def authenticate!(options={})
|
16
|
+
Githubris::API.basic_auth options[:login], options[:password]
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def get_public_gists(options={})
|
20
|
+
quantity = options.delete(:quantity) || 30
|
21
|
+
number_of_overflow_gists = quantity % GISTS_PER_PAGE
|
22
|
+
if quantity > GISTS_PER_PAGE
|
23
|
+
max_page_number = (quantity / GISTS_PER_PAGE) +
|
24
|
+
(number_of_overflow_gists > 0 ? 1 : 0)
|
25
|
+
|
26
|
+
data = Githubris::API.get public_gists_path_for_page(max_page_number)
|
27
|
+
gists = @builder.build(data).
|
28
|
+
concat(get_public_gists(quantity: quantity - GISTS_PER_PAGE))
|
29
|
+
else
|
30
|
+
url = PUBLIC_GISTS_PATH
|
31
|
+
data = Githubris::API.get(url)
|
32
|
+
gists = @builder.build(data)
|
24
33
|
end
|
34
|
+
gists.shift(quantity)
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_user(options={})
|
38
|
+
Githubris::User.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def public_gists_path_for_page page_number
|
42
|
+
"#{PUBLIC_GISTS_PATH}?page=#{page_number}"
|
25
43
|
end
|
26
44
|
end
|
data/lib/githubris/builder.rb
CHANGED
@@ -1,26 +1,35 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
self.build gist_data
|
9
|
-
end
|
10
|
-
else
|
11
|
-
data[:user] = Githubris::User.build data.delete('user')
|
12
|
-
data[:public] = data.delete('public')
|
13
|
-
data[:description] = data.delete('description')
|
14
|
-
data[:files] = data.delete('files').values
|
15
|
-
data[:url] = URI.parse data.delete('url')
|
16
|
-
data[:created_at] = DateTime.parse data.delete('created_at')
|
17
|
-
data[:updated_at] = DateTime.parse data.delete('updated_at')
|
18
|
-
tmp_arr = []
|
19
|
-
data.delete('comments').times { tmp_arr << Githubris::Comment.new }
|
20
|
-
data[:comments] = tmp_arr
|
21
|
-
Githubris::Gist.new data
|
22
|
-
end
|
1
|
+
class Githubris
|
2
|
+
class Builder
|
3
|
+
def build data
|
4
|
+
if data.instance_of? Array
|
5
|
+
build_gists data
|
6
|
+
else
|
7
|
+
build_gist data
|
23
8
|
end
|
24
9
|
end
|
10
|
+
|
11
|
+
def build_gists(data)
|
12
|
+
data.map do |gist|
|
13
|
+
build_gist gist
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_gist(data)
|
18
|
+
data[:user] = build_user(data.delete 'user' )
|
19
|
+
data[:public] = data.delete('public')
|
20
|
+
data[:description] = data.delete('description')
|
21
|
+
data[:files] = data.delete('files').values
|
22
|
+
data[:url] = URI.parse data.delete('url')
|
23
|
+
data[:created_at] = DateTime.parse data.delete('created_at')
|
24
|
+
data[:updated_at] = DateTime.parse data.delete('updated_at')
|
25
|
+
tmp_arr = []
|
26
|
+
data.delete('comments').times { tmp_arr << Githubris::Comment.new }
|
27
|
+
data[:comments] = tmp_arr
|
28
|
+
Githubris::Gist.new data
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_user data
|
32
|
+
Githubris::User.new
|
33
|
+
end
|
25
34
|
end
|
26
35
|
end
|
data/lib/githubris/comment.rb
CHANGED
data/lib/githubris/gist/file.rb
CHANGED
data/lib/githubris/gist.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
|
1
|
+
class Githubris
|
2
2
|
class Gist
|
3
3
|
autoload :File, 'githubris/gist/file'
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def public_gists
|
7
|
-
Githubris::API.call(:gists, :list_public)
|
8
|
-
end
|
9
|
-
|
10
6
|
def default_options
|
11
7
|
{
|
12
|
-
user: Githubris.authenticated_user,
|
13
8
|
files: [],
|
14
9
|
created_at: DateTime.now,
|
15
10
|
updated_at: DateTime.now
|
@@ -51,10 +46,6 @@ module Githubris
|
|
51
46
|
@options[:url]
|
52
47
|
end
|
53
48
|
|
54
|
-
def save
|
55
|
-
Githubris::API.save_gist(self)
|
56
|
-
end
|
57
|
-
|
58
49
|
def public?
|
59
50
|
@options[:public]
|
60
51
|
end
|
data/lib/githubris/issue.rb
CHANGED
data/lib/githubris/repository.rb
CHANGED
data/lib/githubris/user.rb
CHANGED
data/lib/githubris/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class Githubris
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
data/lib/githubris.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
$:.push File.expand_path("../../config", __FILE__)
|
2
2
|
require_relative "githubris/version"
|
3
3
|
|
4
|
-
|
4
|
+
class Githubris
|
5
5
|
autoload :API, 'githubris/api'
|
6
6
|
autoload :Blob, 'githubris/blob'
|
7
|
+
autoload :Builder, 'githubris/builder'
|
7
8
|
autoload :Comment, 'githubris/comment'
|
8
9
|
autoload :Commit, 'githubris/commit'
|
9
|
-
autoload :Config, 'githubris/config'
|
10
10
|
autoload :Event, 'githubris/event'
|
11
11
|
autoload :Gist, 'githubris/gist'
|
12
12
|
autoload :Issue, 'githubris/issue'
|
@@ -18,21 +18,22 @@ module Githubris
|
|
18
18
|
autoload :Tree, 'githubris/tree'
|
19
19
|
autoload :User, 'githubris/user'
|
20
20
|
|
21
|
-
|
22
|
-
def login(user_name, api_key)
|
23
|
-
@@authenticated_user = Githubris::User.new
|
24
|
-
end
|
21
|
+
attr_reader :authenticated_user
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def initialize
|
24
|
+
@api = Githubris::API.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def authenticate(username, password)
|
28
|
+
@api.authenticate! login: username, password: password
|
29
|
+
@authenticated_user = Githubris::User.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_user(login)
|
33
|
+
@api.get_user(login: login)
|
34
|
+
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
@@authenticated_user
|
33
|
-
rescue
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
end
|
36
|
+
def public_gists(options={})
|
37
|
+
@api.get_public_gists options
|
37
38
|
end
|
38
39
|
end
|
data/spec/githubris/api_spec.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Githubris::API do
|
4
|
-
describe '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it 'takes a single required data requirement' do
|
12
|
-
lambda { subject.call({}) }.should_not raise_error
|
4
|
+
describe '#get_public_gists' do
|
5
|
+
it 'returns an array of gists' do
|
6
|
+
subject.get_public_gists.should be_instance_of Array
|
7
|
+
subject.get_public_gists.each do |gist|
|
8
|
+
gist.should be_instance_of Githubris::Gist
|
9
|
+
end
|
13
10
|
end
|
14
11
|
|
15
|
-
it '
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
subject.call({}, :foo, :bar)
|
20
|
-
subject.call({}, :foo, :bar, :baz)
|
21
|
-
}.should_not raise_error
|
12
|
+
it 'accepts an options hash' do
|
13
|
+
lambda do
|
14
|
+
subject.get_public_gists({foo: 'bar'})
|
15
|
+
end.should_not raise_error
|
22
16
|
end
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
context 'given a quantity option' do
|
19
|
+
it 'returns an array of gists with that quantity' do
|
20
|
+
subject.get_public_gists(quantity: 10).should have(10).items
|
21
|
+
subject.get_public_gists(quantity: 30).should have(30).items
|
22
|
+
subject.get_public_gists(quantity: 31).should have(31).items
|
23
|
+
subject.get_public_gists(quantity: 45).should have(45).items
|
24
|
+
subject.get_public_gists(quantity: 61).should have(61).items
|
25
|
+
end
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -1,26 +1,42 @@
|
|
1
|
-
require 'githubris/builder'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe Githubris::
|
5
|
-
|
6
|
-
|
3
|
+
describe Githubris::Builder do
|
4
|
+
let(:gist_collection_data) { Githubris::SpecHelper.gist_collection_data }
|
5
|
+
let(:gist_data) { Githubris::SpecHelper.gist_data }
|
6
|
+
|
7
|
+
describe '#build' do
|
7
8
|
|
8
9
|
context 'when passed a collection of gist data' do
|
9
|
-
|
10
|
-
Githubris::
|
10
|
+
it 'delegates to #build_gists' do
|
11
|
+
Githubris::Builder.any_instance.stub(:build_gists)
|
12
|
+
subject.build gist_collection_data
|
13
|
+
subject.should have_received(:build_gists).with gist_collection_data
|
11
14
|
end
|
15
|
+
end
|
12
16
|
|
13
|
-
|
17
|
+
context 'when passed the data for a single gist' do
|
18
|
+
it 'delegates to #build_gist' do
|
19
|
+
Githubris::Builder.any_instance.stub(:build_gist)
|
20
|
+
subject.build gist_data
|
21
|
+
subject.should have_received(:build_gist).with gist_data
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
14
25
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
26
|
+
describe '#build_gists' do
|
27
|
+
it 'is an array of gists' do
|
28
|
+
gists = subject.build_gists(gist_collection_data)
|
29
|
+
gists.should be_instance_of Array
|
30
|
+
gists.each do |gist|
|
31
|
+
gist.should be_instance_of Githubris::Gist
|
19
32
|
end
|
20
33
|
end
|
34
|
+
end
|
21
35
|
|
22
|
-
|
23
|
-
|
36
|
+
|
37
|
+
describe '#build_gist' do
|
38
|
+
context 'schema' do
|
39
|
+
subject { Githubris::Builder.new.build gist_data }
|
24
40
|
|
25
41
|
it { should be_instance_of Githubris::Gist }
|
26
42
|
it { should be_public }
|
@@ -34,7 +50,7 @@ describe Githubris::GistBuilder do
|
|
34
50
|
end
|
35
51
|
|
36
52
|
context 'when passed a specific gist' do
|
37
|
-
subject { Githubris::
|
53
|
+
subject { Githubris::Builder.new.build gist_data }
|
38
54
|
|
39
55
|
it 'is public' do
|
40
56
|
subject.should be_public
|
data/spec/githubris/gist_spec.rb
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Githubris::Gist do
|
4
|
-
describe '.public_gists' do
|
5
|
-
context 'when there are a few gists' do
|
6
|
-
it 'is an array of gists' do
|
7
|
-
Githubris::API.stub(:call => [Githubris::Gist.new, Githubris::Gist.new])
|
8
|
-
Githubris::Gist.public_gists.each do |gist|
|
9
|
-
gist.should be_instance_of Githubris::Gist
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
4
|
|
15
5
|
context 'instance methods' do
|
16
6
|
subject { gist }
|
@@ -20,18 +10,6 @@ describe Githubris::Gist do
|
|
20
10
|
DateTime.stub(:now => DateTime.new(2012, 12, 21, 12, 0, 0))
|
21
11
|
gist.created_at.should eql DateTime.now
|
22
12
|
end
|
23
|
-
context "with a user is authenticated" do
|
24
|
-
it 'new gists belong to the authenticated user' do
|
25
|
-
Githubris.stub(:authenticated_user => Githubris::User.new )
|
26
|
-
gist.user.should eql Githubris.authenticated_user
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with no authenticated user' do
|
31
|
-
it 'is nil' do
|
32
|
-
gist.user.should be_nil
|
33
|
-
end
|
34
|
-
end
|
35
13
|
|
36
14
|
context 'Gist owned by Isaac' do
|
37
15
|
subject { Githubris::Gist.new user: user }
|
@@ -50,14 +28,6 @@ describe Githubris::Gist do
|
|
50
28
|
end
|
51
29
|
|
52
30
|
its(:files) { should have(1).items }
|
53
|
-
|
54
|
-
describe 'saving' do
|
55
|
-
it 'gets sent to github' do
|
56
|
-
Githubris::API.stub(:save_gist)
|
57
|
-
subject.save
|
58
|
-
Githubris::API.should have_received(:save_gist).with(subject)
|
59
|
-
end
|
60
|
-
end
|
61
31
|
end
|
62
32
|
end
|
63
33
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Githubris do
|
4
|
+
describe '#authenticate' do
|
5
|
+
before do
|
6
|
+
Githubris::API.stub(:basic_auth => Githubris::User.new)
|
7
|
+
subject.authenticate('username', 'password')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'authenticates via Basic Auth' do
|
11
|
+
Githubris::API.should have_received(:basic_auth).with('username', 'password')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'sets the authenticated user' do
|
15
|
+
subject.authenticated_user.should_not be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#find_user' do
|
20
|
+
it 'requests gets user from githubris api' do
|
21
|
+
user = Githubris::User.new(login: "frank")
|
22
|
+
Githubris::API.any_instance.stub(:get_user).and_return(user)
|
23
|
+
subject.find_user("frank").should == user
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns a user' do
|
27
|
+
subject.find_user('frank').should be_instance_of Githubris::User
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#public_gists' do
|
32
|
+
it 'should contain only gists' do
|
33
|
+
subject.public_gists.each do |gist|
|
34
|
+
gist.should be_instance_of Githubris::Gist
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can take an options hash' do
|
39
|
+
lambda { subject.public_gists(foo: 'bar') }.should_not raise_error
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'delegates and passes the options hash to the API' do
|
43
|
+
Githubris::API.any_instance.stub(:get_public_gists)
|
44
|
+
subject.public_gists({foo: 'bar'})
|
45
|
+
subject.instance_variable_get(:@api).should have_received(:get_public_gists).with({foo: 'bar'})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
require 'rspec-spies'
|
2
|
-
require 'pry'
|
3
2
|
require 'fakeweb'
|
3
|
+
require 'simplecov'
|
4
4
|
require 'githubris'
|
5
5
|
|
6
6
|
require 'support/fixtures'
|
7
7
|
require 'support/fakeweb_responses'
|
8
8
|
require 'support/custom_matchers'
|
9
|
+
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter '/spec/'
|
12
|
+
add_filter '/features/'
|
13
|
+
add_filter '/pkg/'
|
14
|
+
add_filter '/coverage/'
|
15
|
+
end
|
@@ -2,60 +2,5 @@ require 'fakeweb'
|
|
2
2
|
|
3
3
|
FakeWeb.allow_net_connect = false
|
4
4
|
FakeWeb.register_uri(:get, 'https://api.github.com/', :body => '{}')
|
5
|
-
FakeWeb.register_uri(:get,
|
6
|
-
|
7
|
-
{
|
8
|
-
"url": "https://api.github.com/gists/2",
|
9
|
-
"id": "2",
|
10
|
-
"description": "description of gist number two",
|
11
|
-
"public": true,
|
12
|
-
"user": {
|
13
|
-
"login": "rocktocat",
|
14
|
-
"id": 1,
|
15
|
-
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
16
|
-
"gravatar_id": "somehexcode",
|
17
|
-
"url": "https://api.github.com/users/octocat"
|
18
|
-
},
|
19
|
-
"files": {
|
20
|
-
"ring.erl": {
|
21
|
-
"size": 932,
|
22
|
-
"filename": "ring.erl",
|
23
|
-
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
|
24
|
-
"content": "contents of gist"
|
25
|
-
}
|
26
|
-
},
|
27
|
-
"comments": 0,
|
28
|
-
"html_url": "https://gist.github.com/1",
|
29
|
-
"git_pull_url": "git://gist.github.com/1.git",
|
30
|
-
"git_push_url": "git@gist.github.com:1.git",
|
31
|
-
"created_at": "2010-04-14T02:15:15Z"
|
32
|
-
},
|
33
|
-
{
|
34
|
-
"url": "https://api.github.com/gists/1",
|
35
|
-
"id": "1",
|
36
|
-
"description": "description of gist",
|
37
|
-
"public": true,
|
38
|
-
"user": {
|
39
|
-
"login": "octocat",
|
40
|
-
"id": 1,
|
41
|
-
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
42
|
-
"gravatar_id": "somehexcode",
|
43
|
-
"url": "https://api.github.com/users/octocat"
|
44
|
-
},
|
45
|
-
"files": {
|
46
|
-
"ring.erl": {
|
47
|
-
"size": 932,
|
48
|
-
"filename": "ring.erl",
|
49
|
-
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
|
50
|
-
"content": "contents of gist"
|
51
|
-
}
|
52
|
-
},
|
53
|
-
"comments": 0,
|
54
|
-
"html_url": "https://gist.github.com/1",
|
55
|
-
"git_pull_url": "git://gist.github.com/1.git",
|
56
|
-
"git_push_url": "git@gist.github.com:1.git",
|
57
|
-
"created_at": "2010-04-14T02:15:15Z"
|
58
|
-
}
|
59
|
-
]
|
60
|
-
BODY
|
61
|
-
)
|
5
|
+
FakeWeb.register_uri(:get, /gists\/public(?:[^?]*\?page=(\d+))?/,
|
6
|
+
:body => File.open("spec/support/public_gists_page_#{$1 || 1}.json", 'r') {|f| f.read })
|
data/spec/support/fixtures.rb
CHANGED