githubris 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ tags
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@githubris --create
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem 'cucumber'
5
+ gem 'rspec', '~> 2.8.0'
6
+ gem 'rspec-spies'
7
+ gem 'fakeweb'
8
+ gem 'pry'
9
+ gem 'pry-doc'
10
+ end
11
+ gemspec
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ #Githubris
2
+
3
+ This is the best github API wrapper ever.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new :spec do |t|
5
+ t.rspec_opts = "--color --format=documentation"
6
+ end
7
+
8
+ task :default => :spec
data/config/base.yml ADDED
@@ -0,0 +1 @@
1
+ base_uri: 'https://api.github.com'
data/config/gists.yml ADDED
@@ -0,0 +1,13 @@
1
+ gists:
2
+ list_public_user:
3
+ method: 'get'
4
+ path: '/users/:user/gists'
5
+ list_public:
6
+ method: 'get'
7
+ path: '/gists'
8
+ list_authentic_user:
9
+ method: 'get'
10
+ path: '/gists'
11
+ list_authentic_user_starred:
12
+ method: 'get'
13
+ path: '/gists/starred'
data/config.yml ADDED
@@ -0,0 +1 @@
1
+ base_uri: 'https://api.github.com/'
data/githubris.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ $:.push File.expand_path("../config", __FILE__)
4
+ require "githubris/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "githubris"
8
+ s.version = Githubris::VERSION
9
+ s.authors = ["Isaac Sanders"]
10
+ s.email = ["isaac@isaacbfsanders.com"]
11
+ s.homepage = "http://isaacbfsanders.com/githubris"
12
+ s.summary = %q{Githubris is meant to make Github API interaction a breeze.}
13
+ s.description = %q{Githubris is meant to make Github API interaction a breeze.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency('httparty', '~> 0.8.1')
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'httparty'
2
+
3
+ module Githubris
4
+ class API
5
+ include HTTParty
6
+ base_uri(Githubris::Config[:base_uri])
7
+
8
+ def self.call(data, *args)
9
+
10
+ options = {data: data}
11
+ unless args.empty?
12
+ options.merge! args.inject(Githubris::Config) {|config, key|
13
+ config[key]
14
+ }
15
+ end
16
+ Githubris::API.resolve options
17
+ end
18
+
19
+ def self.resolve options
20
+ method = options[:method].intern
21
+ path = URI.parse(options[:path])
22
+ puts "#{method} #{path}"
23
+ Githubris::API.send(method, path)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Githubris
2
+ class GistBuilder
3
+ class << self
4
+ def build data
5
+ return data if data.instance_of? Githubris::Gist
6
+ if data.instance_of? Array
7
+ data.map do |gist_data|
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
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ module Githubris
2
+ class Comment
3
+ def self.build comment_data
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+
3
+ module Githubris
4
+ module Config
5
+ @@config = {}
6
+ @@config.merge! YAML.load_file('config/base.yml')
7
+ @@config.merge! YAML.load_file('config/gists.yml')
8
+
9
+ def self.[] (key)
10
+ @@config[key.to_s]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Githubris
2
+ class Gist
3
+ class File
4
+ def self.build data
5
+ new
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,66 @@
1
+ module Githubris
2
+ class Gist
3
+ autoload :File, 'githubris/gist/file'
4
+
5
+ class << self
6
+ def public_gists
7
+ Githubris::API.call(:gists, :list_public)
8
+ end
9
+
10
+ def default_options
11
+ {
12
+ user: Githubris.authenticated_user,
13
+ files: [],
14
+ created_at: DateTime.now,
15
+ updated_at: DateTime.now
16
+ }
17
+ end
18
+ end
19
+
20
+ def initialize options={}
21
+ options.merge! Githubris::Gist.default_options do |given_key, given_value|
22
+ if Githubris::Gist.default_options.has_key? given_key
23
+ given_value
24
+ end
25
+ end
26
+
27
+ @options = options
28
+ end
29
+
30
+ def user
31
+ @options[:user]
32
+ end
33
+
34
+ def created_at
35
+ @options[:created_at]
36
+ end
37
+
38
+ def updated_at
39
+ @options[:updated_at]
40
+ end
41
+
42
+ def description
43
+ @options[:description]
44
+ end
45
+
46
+ def files
47
+ @options[:files]
48
+ end
49
+
50
+ def url
51
+ @options[:url]
52
+ end
53
+
54
+ def save
55
+ Githubris::API.save_gist(self)
56
+ end
57
+
58
+ def public?
59
+ @options[:public]
60
+ end
61
+
62
+ def comments
63
+ @options[:comments]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,6 @@
1
+ module Githubris
2
+ class Issue
3
+ autoload :Label, 'githubris/issue/label'
4
+ autoload :Milestone, 'githubris/issue/milestone'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Githubris
2
+ class Organization
3
+ autoload :Team, 'githubris/organization/team'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Githubris
2
+ class Repository
3
+ autoload :Download, 'githubris/repository/download'
4
+ autoload :Fork, 'githubris/repository/fork'
5
+ autoload :Hook, 'githubris/repository/hook'
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Githubris
2
+ class User
3
+ def self.build user_data
4
+ if user_data.instance_of? Githubris::User
5
+ return user_data
6
+ else
7
+ self.new
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Githubris
2
+ VERSION = "0.0.1"
3
+ end
data/lib/githubris.rb ADDED
@@ -0,0 +1,38 @@
1
+ $:.push File.expand_path("../../config", __FILE__)
2
+ require_relative "githubris/version"
3
+
4
+ module Githubris
5
+ autoload :API, 'githubris/api'
6
+ autoload :Blob, 'githubris/blob'
7
+ autoload :Comment, 'githubris/comment'
8
+ autoload :Commit, 'githubris/commit'
9
+ autoload :Config, 'githubris/config'
10
+ autoload :Event, 'githubris/event'
11
+ autoload :Gist, 'githubris/gist'
12
+ autoload :Issue, 'githubris/issue'
13
+ autoload :Organization, 'githubris/organization'
14
+ autoload :PullRequest, 'githubris/pull_request'
15
+ autoload :Reference, 'githubris/reference'
16
+ autoload :Repository, 'githubris/repository'
17
+ autoload :Tag, 'githubris/tag'
18
+ autoload :Tree, 'githubris/tree'
19
+ autoload :User, 'githubris/user'
20
+
21
+ class << self
22
+ def login(user_name, api_key)
23
+ @@authenticated_user = Githubris::User.new
24
+ end
25
+
26
+ def logout
27
+ @@authenticated_user = nil
28
+ end
29
+
30
+ def authenticated_user
31
+ begin
32
+ @@authenticated_user
33
+ rescue
34
+ nil
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Githubris::API do
4
+ describe 'making calls' do
5
+ subject { Githubris::API }
6
+
7
+ before do
8
+ Githubris::API.stub(:resolve)
9
+ end
10
+
11
+ it 'takes a single required data requirement' do
12
+ lambda { subject.call({}) }.should_not raise_error
13
+ end
14
+
15
+ it 'takes multiple arguments' do
16
+ Githubris::Config.stub(:[] => {:bar => {:baz => {}}})
17
+ lambda {
18
+ subject.call({}, :foo)
19
+ subject.call({}, :foo, :bar)
20
+ subject.call({}, :foo, :bar, :baz)
21
+ }.should_not raise_error
22
+ end
23
+
24
+ it 'uses the config' do
25
+ Githubris::Config.stub(:[] => {})
26
+ subject.call({}, :foo)
27
+ Githubris::Config.should have_received(:[]).with(:foo)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ require 'githubris/builder'
2
+ require 'spec_helper'
3
+
4
+ describe Githubris::GistBuilder do
5
+ describe 'build' do
6
+ let(:gist_data) { Githubris::SpecHelper.gist_data }
7
+
8
+ context 'when passed a collection of gist data' do
9
+ subject do
10
+ Githubris::GistBuilder.build Githubris::SpecHelper.gist_collection_data
11
+ end
12
+
13
+ it { should be_instance_of Array }
14
+
15
+ it 'is an array of gists' do
16
+ subject.each do |gist|
17
+ gist.should be_instance_of Githubris::Gist
18
+ end
19
+ end
20
+ end
21
+
22
+ context 'when passed the data for a single gist' do
23
+ subject { Githubris::GistBuilder.build gist_data }
24
+
25
+ it { should be_instance_of Githubris::Gist }
26
+ it { should be_public }
27
+ its(:user) { should be_instance_of Githubris::User }
28
+ its(:description) { should be_instance_of String }
29
+ its(:created_at) { should be_instance_of DateTime }
30
+ its(:updated_at) { should be_instance_of DateTime }
31
+ its(:comments) { should be_instance_of Array }
32
+ its(:files) { should be_instance_of Array }
33
+ its(:url) { should be_kind_of URI }
34
+ end
35
+
36
+ context 'when passed a specific gist' do
37
+ subject { Githubris::GistBuilder.build gist_data }
38
+
39
+ it 'is public' do
40
+ subject.should be_public
41
+ end
42
+
43
+ its(:description) { should eql 'the meaning of gist' }
44
+
45
+ it 'was created at 6:17:13 on July 15, 2008' do
46
+ subject.created_at.should eql DateTime.new(2008, 7, 15, 18, 17, 13)
47
+ end
48
+
49
+ it 'was updated at 2:58:22 on Feburary 22, 2011' do
50
+ subject.updated_at.should eql DateTime.new(2011, 2, 22, 2, 58, 22)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
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
+
15
+ context 'instance methods' do
16
+ subject { gist }
17
+ let(:gist) { Githubris::Gist.new }
18
+
19
+ it 'new gists are created now' do
20
+ DateTime.stub(:now => DateTime.new(2012, 12, 21, 12, 0, 0))
21
+ gist.created_at.should eql DateTime.now
22
+ 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
+
36
+ context 'Gist owned by Isaac' do
37
+ subject { Githubris::Gist.new user: user }
38
+ let(:user) { Githubris::User.new }
39
+ its(:user) { should eql user }
40
+ end
41
+
42
+
43
+ describe 'a gist without files' do
44
+ its(:files) { should be_empty }
45
+ end
46
+
47
+ describe 'a gist created with a file' do
48
+ subject do
49
+ Githubris::Gist.new(files: [stub])
50
+ end
51
+
52
+ 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
+ end
62
+ end
63
+ end
@@ -0,0 +1,8 @@
1
+ require 'rspec-spies'
2
+ require 'pry'
3
+ require 'fakeweb'
4
+ require 'githubris'
5
+
6
+ require 'support/fixtures'
7
+ require 'support/fakeweb_responses'
8
+ require 'support/custom_matchers'
@@ -0,0 +1,27 @@
1
+ RSpec::Matchers.define :be_greater_than do |first|
2
+ match do |actual|
3
+ (actual > first) && (actual < @second)
4
+ end
5
+
6
+ chain :but_less_than do |second|
7
+ @second = second
8
+ end
9
+ end
10
+
11
+ RSpec::Matchers.define :all do |expected|
12
+
13
+ match do |actual|
14
+ @actual = actual
15
+ @actual.all?(&@expectation)
16
+ end
17
+ chain :be_instance_of do |expected_klazz|
18
+ @message = "be instances of #{expected_klazz}"
19
+ @expectation = lambda do |actual|
20
+ actual.instance_of? expected_klazz
21
+ end
22
+ end
23
+
24
+ description do
25
+ "all #{@message}"
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ require 'fakeweb'
2
+
3
+ FakeWeb.allow_net_connect = false
4
+ FakeWeb.register_uri(:get, 'https://api.github.com/', :body => '{}')
5
+ FakeWeb.register_uri(:get, 'https://api.github.com/gists', :body => <<-BODY
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
+ )