gitwrap 1.5.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b82d05ab8d4f25f51a5d68b8a1f2f5c1ddc01f7d
4
- data.tar.gz: 3aa749ef4e59281f9427cd22a33abe2753443be8
3
+ metadata.gz: e63bbc59c205ffa4d8bc459dec63451590c781db
4
+ data.tar.gz: 5302533fef42d2e39dd444e1806aa97a2a493fa1
5
5
  SHA512:
6
- metadata.gz: 167010b5bb68ad87abca383132238dd738aaac365d1d8c90614e5294e20df2df48d39861207f2ea948179794f8f61e3ff6f6519c684f3ad4eec53d0e8da6c357
7
- data.tar.gz: 273dd533699ca08894d4822de726ae4d3750b8b716b7f40597c7fe41ff4311e4e64a0150507e18db878f2e46a237ff49c873ce1cba8bae8e76c070dfc4391492
6
+ metadata.gz: 824c3cce57adec93cde53968b236948cfcd9ad07698568d2e1a5d353f5ebb1266cd3100ac4b7694a6a39827b98403446d9c1509fcbd6045a1b1ccb0a04a106c9
7
+ data.tar.gz: 332ec84c8d561e766e0cc5a3796678c1e5cbfb677822009e51eca047b9bbcb0ed8f84dd8fd38172db23c24287aaa77134b6be1debec6e30ea4be62c3e407f514
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .DS_Store
11
+ *.gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Gitwrap
2
2
 
3
- Welcome to GitWrap! A simple client wrapper that interacts with the GitHub API. What does it do? It basically renders public data from Users, Repositories and Organizations. These include name, email, location, stars, etc.
3
+ Welcome to GitWrap! A simple client wrapper that interacts with the GitHub API. What does it do? It basically renders public data from Users, Repositories and Organizations. These include name, email, location, stars, etc.
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,53 +22,58 @@ Or install it yourself as:
22
22
 
23
23
  After installing the gem just include it in your gemfile and off you go!
24
24
 
25
- The objects are generated automatically. They have a base url to connect to and retrieve data via the DataCreator module, which parses and returns corresponding obejcts to the method calls.
25
+ The objects are generated automatically. They have a base url to connect to and retrieve data via the DataCreator module, which parses and returns corresponding objects to the method calls.
26
26
 
27
27
  Each object method is listed here:
28
28
 
29
29
  ## Users
30
- ```
31
- user = User.fetch_single_user(username)
32
- user = User.fetch_all_users
30
+ ```ruby
31
+ user = Gitwrap::User::fetch_single_user(username)
32
+ users = Gitwrap::User::fetch_all_users(since_id)
33
+ users = Gitwrap::User::fetch_users_by_location(location)
34
+ users = Gitwrap::User::fetch_users_by_language(language)
35
+ users = Gitwrap::User::fetch_users_by_location_and_language(location, language)
33
36
  ```
34
37
 
35
38
  ## Orgs
36
- ```
37
- org = Org.fetch_single_org(organization_name)
38
- org = Org.fetch_all_orgs
39
+ ```ruby
40
+ org = Gitwrap::Org::fetch_single_org(organization_name)
41
+ org = Gitwrap::Org::fetch_all_orgs(since_id)
39
42
  ```
40
43
  ## Repos
41
- ```
42
- repos = Repo.fetch_user_repos(username)
43
- repos = Repo.fetch_org_repos(organization_name)
44
- repos = Repo.fetch_all_repos
45
- repo = Repo.fetch_single_repo(repo_owner, repo_name)
44
+ ```ruby
45
+ repos = Gitwrap::Repo::fetch_user_repos(username)
46
+ repos = Gitwrap::Repo::fetch_org_repos(organization_name)
47
+ repos = Gitwrap::Repo::fetch_all_repos(since_id)
48
+ repo = Gitwrap::Repo::fetch_single_repo(repo_owner, repo_name)
49
+ repos = Gitwrap::Repo::fetch_repos_by_language(language)
46
50
  ```
47
51
 
48
52
  Using the wrapper is simple. Just declare your new objects:
49
- ```
50
- user = User.fetch_single_user(username)
53
+ ```ruby
54
+ user = Gitwrap::User::fetch_single_user(username)
51
55
  ```
52
56
  And call the desired methods:
53
- ```
57
+ ```ruby
54
58
  user.name
55
59
  user.email
56
60
  user.location
57
61
  ```
58
62
 
59
- Each class (Users, Repos and Orgs) has their unique attributes.
63
+ Each class (Users, Repos and Orgs) has its unique attributes.
60
64
 
61
65
  Users have:
62
66
 
63
- ```
67
+ ```ruby
64
68
  user.name
65
69
  user.email
66
70
  user.location
67
71
  user.username
72
+ user...
68
73
  ```
69
- Organizations have:
74
+ Organizations have:
70
75
 
71
- ```
76
+ ```ruby
72
77
  org.id
73
78
  org.name
74
79
  org.site
@@ -76,29 +81,36 @@ org.location
76
81
  org.public_repos
77
82
  org.followers
78
83
  org.members
84
+ org...
79
85
  ```
80
86
 
81
87
  Repos have:
82
- ```
88
+ ```ruby
83
89
  repo.name
84
90
  repo.url
85
91
  repo.language
86
92
  repo.stars
93
+ repo...
87
94
  ```
88
95
 
89
- It is worth noting that due to the Github API format, not all attributes are available to every method call. Such examples are included in the fetch.rb file.
90
-
96
+ It is worth noting that due to the Github API format, not all attributes are available to every method call.
91
97
 
92
98
  ## Contributing
93
99
 
94
100
  1. Fork it!
95
101
  2. Commit your changes.
96
- 3. Create a pull request.
102
+ 3. Create a pull request!
103
+
104
+ ##Heroes
105
+
106
+ ###Oscar Elizondo
107
+
108
+ * http://twitter.com/oehinojosa
109
+ * http://github.com/oelizondo
97
110
 
98
111
  ##Current Version
99
- Version 1.5.0
112
+ Version 2.5.0
100
113
 
101
114
  ## License
102
115
 
103
116
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
104
-
data/gitwrap.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.bindir = "exe"
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
-
29
+ spec.add_dependency "httparty", "~> 0.13.5"
30
30
  spec.add_development_dependency "bundler", "~> 1.10"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  end
@@ -0,0 +1,16 @@
1
+ module Gitwrap
2
+ module Exception
3
+ class APIError < StandardError
4
+ attr_accessor :http_status, :response_body
5
+
6
+ def initialize
7
+ message = "[HTTP #{http_status}] #{response_body}"
8
+ super (message)
9
+ end
10
+ end
11
+
12
+ class ServerError < APIError; end
13
+
14
+ class Clienterror < APIError; end
15
+ end
16
+ end
data/lib/gitwrap/orgs.rb CHANGED
@@ -1,31 +1,33 @@
1
+ require 'gitwrap/error.rb'
2
+
1
3
  module Gitwrap
2
- class Org < GithubConnection
3
- attr_reader :name, :site, :location, :public_repos, :followers, :members, :id
4
- $current_org = 0
5
- $all_orgs = []
4
+ class Org < OpenStruct
5
+ include HTTParty
6
6
 
7
- def initialize(hash)
8
- @id = hash["id"]
9
- @name = hash["login"]
10
- @site = hash["blog"]
11
- @location = hash["location"]
12
- @public_repos = hash["public_repos"]
13
- @followers = hash["followers"]
14
- @members = hash["members"]
15
- end
7
+ base_uri "https://api.github.com/"
8
+ $orgs = []
16
9
 
17
10
  def self.fetch_single_org(organization)
18
- data = open("#{BASE_URL}orgs/#{organization}").open()
19
- data = JSON.parse(data)
20
- org = new(data)
11
+ response = get("/orgs/#{organization}")
12
+ if response.success? then org = new(response) else raise_exception(response.code, response.body) end
21
13
  end
22
14
 
23
- def self.fetch_all_orgs
24
- data = open("#{BASE_URL}organizations?since=#{$current_org}").read()
25
- data = JSON.parse(data)
26
- data.each {|org| $all_orgs << new(org)}
27
- $current_org += orgs.length-1
28
- $all_orgs
15
+ def self.fetch_all_orgs(org_id)
16
+ response = get("/organizations?since=#{org_id}&per_page=100")
17
+ if response.success?
18
+ response = response.parsed_response
19
+ response.each { |org| $orgs << new(org)}
20
+ $orgs
21
+ else
22
+ raise_exception(response.code, response.body)
23
+ end
29
24
  end
25
+
26
+ private
27
+ def raise_exception(code, body)
28
+ raise Gitwrap::Exception::ServerError.new(code, body) if code >= 500
29
+ raise Gitwrap::Exception::ClientError.new(code, body) if code < 500
30
+ end
31
+
30
32
  end
31
- end
33
+ end
data/lib/gitwrap/repos.rb CHANGED
@@ -1,43 +1,66 @@
1
+ require 'gitwrap/error.rb'
2
+
1
3
  module Gitwrap
2
- class Repo < GithubConnection
3
- attr_reader :name, :url, :forks_count, :language, :stars
4
- $current_repo = 0
5
- $all_repos = []
6
- $all_org_repos = []
7
-
8
- def initialize(hash)
9
- @name = hash["name"]
10
- @url = hash["url"]
11
- @forks = hash["forks_count"]
12
- @language = hash["language"]
13
- @stars = hash["stargazers_count"]
14
- end
4
+ class Repo < OpenStruct
5
+ include HTTParty
6
+
7
+ base_uri "https://api.github.com/"
8
+ $repos = []
15
9
 
16
10
  def self.fetch_user_repos(username)
17
- data = open("#{BASE_URL}users/#{username}/repos").read()
18
- data = JSON.parse(data)
19
- repo = new(data)
11
+ $repos = []
12
+ response = get("/users/#{username}/repos")
13
+ if response.success?
14
+ response = response.parsed_response
15
+ response.each {|repo| $repos << new(repo)}
16
+ else
17
+ raise_exception(response.code, response.body)
18
+ end
19
+ $repos
20
20
  end
21
21
 
22
22
  def self.fetch_org_repos(org)
23
- data = open("#{BASE_URL}orgs/#{org}/repos").read()
24
- data = JSON.parse(data)
25
- data.each {|repo| $all_org_repos << new(repo) }
26
- $all_org_repos
23
+ response = get("/orgs/#{org}/repos")
24
+ if response.success?
25
+ response = response.parsed_response
26
+ response.each {|repo| $repos << new(repo)}
27
+ else
28
+ raise_exception(response.code, response.body)
29
+ end
30
+ $repos
27
31
  end
28
32
 
29
- def self.fetch_all_repos
30
- data = open("#{BASE_URL}repositories").read()
31
- data = JSON.parse(data)
32
- data.each { |repo| $all_repos << new(repo) }
33
- $current_repo += repos.length-1
34
- $all_repos
33
+ def self.fetch_all_repos(repo_id)
34
+ response = get("/repositories?since#{repo_id}")
35
+ if response.success?
36
+ response = response.parsed_response
37
+ response.each {|repo| $repos << new(repo)}
38
+ else
39
+ raise_exception(response.code, response.body)
40
+ end
41
+ $repos
35
42
  end
36
43
 
37
44
  def self.fetch_single_repo(username, repo)
38
- data = open("#{BASE_URL}repos/#{username}/#{repo}").read()
39
- data = JSON.parse(data)
40
- repo = new(data)
45
+ response = get("/repos/#{username}/#{repo}")
46
+ if response.success? then repo = new(response) else raise_exception end
41
47
  end
48
+
49
+ def self.fetch_repos_by_language(language)
50
+ response = get("/search/repositories?q=language:#{language}&sort=stars&order=desc&per_page=100")
51
+ if response.success?
52
+ response = response["items"]
53
+ response.each { |repo| $repos << new(repo)}
54
+ else
55
+ raise_exception(response.code, response.body)
56
+ end
57
+ $repos
58
+ end
59
+
60
+ private
61
+ def raise_exception(code, body)
62
+ raise Gitwrap::Exception::ServerError.new(code, body) if code >= 500
63
+ raise Gitwrap::Exception::ClientError.new(code, body) if code < 500
64
+ end
42
65
  end
43
- end
66
+ end
data/lib/gitwrap/users.rb CHANGED
@@ -1,28 +1,67 @@
1
+ require 'gitwrap/error.rb'
2
+
1
3
  module Gitwrap
2
- class User < GithubConnection
3
- attr_reader :name, :location, :email, :username
4
- $current_id = 0
5
- $all_users = []
6
-
7
- def initialize(hash={})
8
- @name = hash['name']
9
- @location = hash['location']
10
- @email = hash['email']
11
- @username = hash['login']
12
- end
4
+ class User < OpenStruct
5
+ include HTTParty
6
+
7
+ base_uri "https://api.github.com/"
8
+ $users = []
13
9
 
14
10
  def self.fetch_single_user(username)
15
- data = open("#{BASE_URL}users/#{username}").read()
16
- data = JSON.parse(data)
17
- user = new(data)
11
+ response = get("/users/#{username}")
12
+ if response.success? then user = new(response) else raise_exception(response.code, response.body) end
13
+ end
14
+
15
+ def self.fetch_all_users(id)
16
+ response = get("/users?since=#{id}")
17
+ if response.success?
18
+ response = response.parsed_response
19
+ response.each { |user| $users << new(user) }
20
+ else
21
+ raise_exception(response.code, response.body)
22
+ end
23
+ $users
24
+ end
25
+
26
+ def self.fetch_users_by_language(language)
27
+ response = get("/search/users?q=language:#{language}&per_page=100")
28
+ if response.success?
29
+ response = response["items"]
30
+ response.each {|user| $users << new(user)}
31
+ else
32
+ raise_exception(response.code, response.body)
33
+ end
34
+ $users
35
+ end
36
+
37
+ def self.fetch_users_by_location(location)
38
+ response = get("/search/users?q=location:#{location}&per_page=100")
39
+ if response.success?
40
+ response = response["items"]
41
+ response.each { |user| $users << new(user) }
42
+ else
43
+ raise_exception(response.code, response.body)
44
+ end
45
+ $users
18
46
  end
19
47
 
20
- def self.fetch_all_users
21
- data = open("#{BASE_URL}users?since=#{$current_id}").read()
22
- data = JSON.parse(data)
23
- data.each {|user| $all_users << new(user)}
24
- $current_id += $all_users.length-1
25
- $all_users
48
+ def self.fetch_users_by_location_and_language(location, language)
49
+ response = get("/search/users?q=location:#{location}+language:#{language}&per_page=100")
50
+ if response.success?
51
+ response = response["items"]
52
+ response.each { |user| $users << new(user) }
53
+ else
54
+ raise_exception(response.code, response.body)
55
+ end
56
+ $users
26
57
  end
58
+
59
+ private
60
+
61
+ def raise_exception(code, body)
62
+ raise Gitwrap::Exception::ServerError.new(code, body) if code >= 500
63
+ raise Gitwrap::Exception::ClientError.new(code, body) if code < 500
64
+ end
65
+
27
66
  end
28
- end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Gitwrap
2
- VERSION = "1.5.0"
2
+ VERSION = "2.5.0"
3
3
  end
data/lib/gitwrap.rb CHANGED
@@ -1,9 +1,10 @@
1
- require 'json'
2
- require 'open-uri'
3
- require "gitwrap/version"
1
+ require 'httparty'
4
2
 
5
3
  module Gitwrap
6
- class GithubConnection
7
- BASE_URL = "https://api.github.com/"
8
- end
9
4
  end
5
+
6
+ require "gitwrap/version"
7
+ require "gitwrap/orgs.rb"
8
+ require "gitwrap/users.rb"
9
+ require "gitwrap/repos.rb"
10
+ require "gitwrap/error.rb"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitwrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oscarmarcelo95
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-27 00:00:00.000000000 Z
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.5
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -55,9 +69,7 @@ files:
55
69
  - bin/setup
56
70
  - gitwrap.gemspec
57
71
  - lib/gitwrap.rb
58
- - lib/gitwrap/.DS_Store
59
- - lib/gitwrap/data_creator.rb
60
- - lib/gitwrap/fetch.rb
72
+ - lib/gitwrap/error.rb
61
73
  - lib/gitwrap/orgs.rb
62
74
  - lib/gitwrap/repos.rb
63
75
  - lib/gitwrap/users.rb
Binary file
@@ -1,50 +0,0 @@
1
- # module DataCreator
2
- # $parsed_array = []
3
-
4
- # def parse_data(url)
5
- # data = open(url).read()
6
- # data = JSON.parse(data)
7
- # end
8
-
9
- # def create_user(url)
10
- # User.new(parse_data(url))
11
- # end
12
-
13
- # def create_many_users(url)
14
- # data = parse_data(url)
15
- # data.each {|user| $parsed_array << User.new(user) }
16
- # $parsed_array
17
- # end
18
-
19
- # def create_org(url)
20
- # Org.new(parse_data(url))
21
- # end
22
-
23
- # def create_many_orgs(url)
24
- # data = parse_data(url)
25
- # data.each { |org| $parsed_array << Org.new(org)}
26
- # $parsed_array
27
- # end
28
-
29
- # def create_user_repos(url)
30
- # data = parse_data(url)
31
- # data.each { |repo| $parsed_array << Repo.new(repo)}
32
- # $parsed_array
33
- # end
34
-
35
- # def create_org_repos(url)
36
- # data = parse_data(url)
37
- # data.each { |repo| $parsed_array << Repo.new(repo)}
38
- # $parsed_array
39
- # end
40
-
41
- # def create_many_repos(url)
42
- # data = parse_data(url)
43
- # data.each { |repo| $parsed_array << Repo.new(repo)}
44
- # $parsed_array
45
- # end
46
-
47
- # def create_single_repo(url)
48
- # Repo.new(parse_data(url))
49
- # end
50
- # end
data/lib/gitwrap/fetch.rb DELETED
@@ -1,63 +0,0 @@
1
- # require 'json'
2
- # require 'open-uri'
3
- # require './base_connection.rb'
4
- # # puts "Type user's username "
5
- # # username = gets.chomp
6
- # # puts '---------USERS--------'
7
-
8
- # u = User.fetch_single_user('oelizondo')
9
- # puts "Name: #{u.name}"
10
- # puts "Email: #{u.email}"
11
- # puts "Location: #{u.location}"
12
- # puts "Username: #{u.username}"
13
-
14
- # # puts '-----------------'
15
-
16
- # # all_users = User.fetch_all_users()
17
- # # all_users.each do |user|
18
- # # puts "Username: #{user.username}"
19
- # # end
20
-
21
- # # puts '--------ORGS---------'
22
-
23
- # # org = Org.fetch_single_org('IcaliaLabs')
24
- # # puts "Name: #{org.name}"
25
- # # puts "Site: #{org.site}"
26
- # # puts "Location: #{org.location}"
27
- # # puts "Public Repositories: #{org.public_repos}"
28
- # # puts "Followers: #{org.followers}"
29
- # # puts "Members: #{org.members}"
30
-
31
- # # orgs = Org.fetch_all_orgs()
32
- # # orgs.each do |org|
33
- # # puts "Name: #{org.name}"
34
- # # end
35
-
36
- # # puts '--------REPOS---------'
37
-
38
- # # repos = Repo.fetch_user_repos('oelizondo')
39
- # # repos.each do |repo|
40
- # # puts "Repository name: #{repo.name}"
41
- # # end
42
-
43
- # # puts '-----------------'
44
-
45
- # # repos = Repo.fetch_org_repos('IcaliaLabs')
46
- # # repos.each do |repo|
47
- # # puts "Name: #{repo.name}"
48
- # # puts "Language: #{repo.language}"
49
- # # puts "Stars: #{repo.stars}"
50
- # # end
51
- # # puts '-----------------'
52
-
53
- # # repos = Repo.fetch_all_repos()
54
- # # repos.each do |repo|
55
- # # puts "Name: #{repo.name}"
56
- # # end
57
-
58
- # # puts '-----------------'
59
-
60
- # # repo = Repo.fetch_single_repo('oelizondo', 'Angular_1')
61
- # # puts "Name: #{repo.name}"
62
- # # puts "Language: #{repo.language}"
63
- # # puts "Stars #{repo.stars}"