scroauth 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/lib/scro/auth.rb CHANGED
@@ -3,6 +3,17 @@ require "rest_client"
3
3
 
4
4
  module Scro
5
5
  module Auth
6
+ class RequestError < StandardError; end
7
+
8
+ def self.endpoint
9
+ "https://github.com/api/v2/json/"
10
+ end
11
+
12
+ def self.get(token, path)
13
+ response = RestClient.get("#{endpoint}#{path}?access_token=#{token}")
14
+ raise RequestError, response.inspect unless response.code == 200
15
+ JSON.parse(response)
16
+ end
6
17
  end
7
18
  end
8
19
 
@@ -0,0 +1,8 @@
1
+ module Scro
2
+ module Auth
3
+ class Repository
4
+ def initialize(owner, name, url, is_private)
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,8 +1,43 @@
1
1
  module Scro
2
2
  module Auth
3
+ class Plan < Struct.new(:name, :collaborators, :space, :private_repos); end
4
+
3
5
  class User
6
+ attr_reader :id, :login, :name, :company, :location, :email, :blog,
7
+ :following_count, :followers_count, :disk_usage,
8
+ :public_gist_count, :public_repo_count, :collaborators,
9
+ :private_gist_count, :owned_private_repo_count, :total_private_repo_count
10
+ :plan
11
+
12
+ attr_reader :user_json
13
+
4
14
  def initialize(login, token)
15
+ raise RequestError, "Token not configured" if token.nil? || token.empty?
5
16
  @login, @token = login, token
17
+
18
+ discover
19
+ end
20
+
21
+ def repos
22
+ @repos ||= get("repos/show/#{@login}")['repositories']
23
+ end
24
+
25
+ def watched_repos
26
+ @watched_repos ||= get("repos/watched/#{@login}")['repositories']
27
+ end
28
+
29
+ private
30
+
31
+ def discover
32
+ @user_json = get("user/show/#{@login}")['user']
33
+
34
+ user_json.each do |key, value|
35
+ instance_variable_set("@key", value)
36
+ end
37
+ end
38
+
39
+ def get(path)
40
+ Scro::Auth.get(@token, path)
6
41
  end
7
42
  end
8
43
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scroauth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Corey Donohoe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-03 00:00:00 -07:00
18
+ date: 2010-06-04 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ extra_rdoc_files:
61
61
  files:
62
62
  - LICENSE
63
63
  - README.md
64
+ - lib/scro/auth/repository.rb
64
65
  - lib/scro/auth/user.rb
65
66
  - lib/scro/auth.rb
66
67
  - lib/scroauth.rb