Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Github connection class and test.
- Loading branch information
1 parent
6a5d7a4
commit 9728617
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'rest_client' | ||
require 'json' | ||
|
||
module GithubBackup | ||
class Github | ||
|
||
class << self | ||
def api_url | ||
'https://api.github.com' | ||
end | ||
end | ||
|
||
attr_accessor :connection, :username, :password | ||
|
||
def initialize(username, password) | ||
self.username = username | ||
self.password = password | ||
|
||
self.connection = RestClient::Resource.new Github.api_url, :user => username, :password => password | ||
end | ||
|
||
# Return a list of the | ||
def repositories | ||
JSON::parse(connection["orgs/#{username}/repos"].get).collect do |repo_hash| | ||
Repository.new(:ssh_url => repo_hash['ssh_url'], :private => repo_hash['private']) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'test_helper' | ||
require 'fakeweb' | ||
|
||
class GithubBackup::GithubTest < Test::Unit::TestCase | ||
|
||
def setup | ||
FakeWeb.allow_net_connect = false | ||
FakeWeb.register_uri(:get, GithubBackup::Github.api_url, :body => "Unauthorized", :status => ["401", "Unauthorized"]) | ||
FakeWeb.register_uri(:get, 'https://johnnytest:sOOperSecret@api.github.com/orgs/johnnytest/repos', :body => organization_json, :content_type => "application/json") | ||
end | ||
|
||
def teardown | ||
FakeWeb.allow_net_connect = true | ||
end | ||
|
||
def test_repositories | ||
github = GithubBackup::Github.new('johnnytest', 'sOOperSecret') | ||
assert github.repositories.respond_to?(:size) | ||
assert github.repositories.size > 0 | ||
end | ||
|
||
def organization_json | ||
@org_contents ||= File.open(File.join(File.expand_path(File.dirname(__FILE__)), 'fixtures', 'repositories_listing.json')).read | ||
end | ||
|
||
end |