gitwrap 0.2.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e22bb9a5b5d7f00b0ef3871401e15b06da7e663
4
+ data.tar.gz: 3d8432e0d0d93a2e093b5835d94a234c4b1e904a
5
+ SHA512:
6
+ metadata.gz: 76a0a1cbc65b62444860b7f0576a294ce74374d432568f3a0cc4e7e75def0497bd80107b303561479270428d34ca274438ab8a22d0b44ed0ee314df703d99990
7
+ data.tar.gz: 493e10f23b06a94f07ddd1db57f0d670f75e3e0021a8849e73e11941f86c49517f7ac2015a8e95d24b389f784e99cd941faaca55f751e83791c7a21efa353fc3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gitwrap.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 oscarmarcelo95
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Gitwrap
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitwrap`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gitwrap'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gitwrap
22
+
23
+ ## Usage
24
+
25
+ After installing the gem just require the 'dependencies' file that wraps together the whole application and off you go!
26
+
27
+ The obejcts generated Automatically have a base url to connect to and retrieve data via the DataCreator module, which parses and returns corresponding obejcts to the method calls.
28
+
29
+ Each object method is listed here:
30
+
31
+ ## User
32
+ ```
33
+ user = User.fetch_single_user(username)
34
+ user = User.fetch_all_users
35
+ ```
36
+
37
+ ## Orgs
38
+ ```
39
+ org = Org.fetch_single_org(organization_name)
40
+ org = Org.fetch_all_orgs
41
+ ```
42
+ ## Repos
43
+ ```
44
+ repos = Repo.fetch_user_repos(username)
45
+ repos = Repo.fetch_org_repos(organization_name)
46
+ repos = Repo.fetch_all_repos
47
+ repo = Repo.fetch_single_repo(repo_owner, repo_name)
48
+ ```
49
+
50
+ Using the wrapper is simple. Just declare your new objects:
51
+ ```
52
+ user = User.fetch_single_user(username)
53
+ ```
54
+ And call the desired methods:
55
+ ```
56
+ user.name
57
+ user.email
58
+ user.location
59
+ ```
60
+
61
+ Each class (Users, Repos and Orgs) has their unique attributes
62
+
63
+ User has:
64
+
65
+ ```
66
+ user.name
67
+ user.email
68
+ user.location
69
+ user.username
70
+ ```
71
+ Organizations have:
72
+
73
+ ```
74
+ org.id
75
+ org.name
76
+ org.site
77
+ org.location
78
+ org.public_repos
79
+ org.followers
80
+ org.members
81
+ ```
82
+
83
+ Repos have:
84
+ ```
85
+ repo.name
86
+ repo.url
87
+ repo.language
88
+ repo.stars
89
+ ```
90
+
91
+ 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.
92
+
93
+ ## Development
94
+
95
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+
97
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
98
+
99
+ ## Contributing
100
+
101
+ Bug reports and pull requests are welcome on GitHub at https://github.com/oelizondo/gitwrap. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
102
+
103
+
104
+ ## License
105
+
106
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
107
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gitwrap"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/gitwrap.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gitwrap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gitwrap"
8
+ spec.version = Gitwrap::VERSION
9
+ spec.authors = ["oscarmarcelo95"]
10
+ spec.email = ["oscarmarcelo95@gmail.com"]
11
+
12
+ spec.summary = %q{Client that connects to Github's API.}
13
+ spec.description = %q{Gitwrap is amazing to work with information the Github API provides.}
14
+ spec.homepage = "https://github.com/oelizondo/gitwrap"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
Binary file
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH << '.'
2
+ require_relative 'data_creator.rb'
3
+
4
+ class GithubConnection
5
+ include DataCreator
6
+ BASE_URL = "https://api.github.com/"
7
+ end
@@ -0,0 +1,24 @@
1
+ class Org < GithubConnection
2
+ attr_accessor :name, :site, :location, :public_repos, :followers, :members, :id
3
+ $current_org = 0
4
+
5
+ def initialize(hash)
6
+ @id = hash["id"]
7
+ @name = hash["login"]
8
+ @site = hash["blog"]
9
+ @location = hash["location"]
10
+ @public_repos = hash["public_repos"]
11
+ @followers = hash["followers"]
12
+ @members = hash["members"]
13
+ end
14
+
15
+ def self.fetch_single_org(organization)
16
+ org = Org.new({}).create_org("#{BASE_URL}orgs/#{organization}")
17
+ end
18
+
19
+ def self.fetch_all_orgs
20
+ orgs = Org.new({}).create_many_orgs("#{BASE_URL}organizations?since=#{$current_org}")
21
+ $current_org += orgs.length-1
22
+ orgs
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ class Repo < GithubConnection
2
+ attr_accessor :name, :url, :forks_count, :language, :stars
3
+ $current_repo = 0
4
+
5
+ def initialize(hash)
6
+ @name = hash["name"]
7
+ @url = hash["url"]
8
+ @forks = hash["forks_count"]
9
+ @language = hash["language"]
10
+ @stars = hash["stargazers_count"]
11
+ end
12
+
13
+ def self.fetch_user_repos(username)
14
+ repo = Repo.new({}).create_user_repos("#{BASE_URL}users/#{username}/repos")
15
+ end
16
+
17
+ def self.fetch_org_repos(org)
18
+ repos = Repo.new({}).create_org_repos("#{BASE_URL}orgs/#{org}/repos")
19
+ end
20
+
21
+ def self.fetch_all_repos
22
+ repos = Repo.new({}).create_many_repos("#{BASE_URL}repositories")
23
+ $current_repo += repos.length-1
24
+ repos
25
+ end
26
+
27
+ def self.fetch_single_repo(username, repo)
28
+ repo = Repo.new({}).create_single_repo("#{BASE_URL}repos/#{username}/#{repo}")
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ class User < GithubConnection
2
+ attr_accessor :name, :location, :email, :username
3
+ $current_id = 0
4
+
5
+ def initialize(hash)
6
+ @name = hash['name']
7
+ @location = hash['location']
8
+ @email = hash['email']
9
+ @username = hash['login']
10
+ end
11
+
12
+ def self.fetch_single_user(username)
13
+ user = User.new({}).create_user("#{BASE_URL}users/#{username}")
14
+ end
15
+
16
+ def self.fetch_all_users
17
+ $all_users = User.new({}).create_many_users("#{BASE_URL}users?since=#{$current_id}")
18
+ $current_id += $all_users.length-1
19
+ $all_users
20
+ end
21
+ end
@@ -0,0 +1,51 @@
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
+
51
+ end
@@ -0,0 +1,7 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+ require './lib/classes/base_connection.rb'
4
+ require './lib/data_creator.rb'
5
+ require './lib/classes/users.rb'
6
+ require './lib/classes/orgs.rb'
7
+ require './lib/classes/repos.rb'
@@ -0,0 +1,63 @@
1
+ require './dependencies.rb'
2
+
3
+ # puts "Type user's username "
4
+ # username = gets.chomp
5
+
6
+ # puts '---------USERS--------'
7
+
8
+ # u = User.fetch_single_user(username)
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}"
@@ -0,0 +1,3 @@
1
+ module Gitwrap
2
+ VERSION = "0.2.0"
3
+ end
data/lib/gitwrap.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "gitwrap/version"
2
+ require "gitwrap/dependencies"
3
+ module Gitwrap
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitwrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - oscarmarcelo95
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Gitwrap is amazing to work with information the Github API provides.
42
+ email:
43
+ - oscarmarcelo95@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - gitwrap.gemspec
57
+ - lib/gitwrap.rb
58
+ - lib/gitwrap/.DS_Store
59
+ - lib/gitwrap/classes/base_connection.rb
60
+ - lib/gitwrap/classes/orgs.rb
61
+ - lib/gitwrap/classes/repos.rb
62
+ - lib/gitwrap/classes/users.rb
63
+ - lib/gitwrap/data_creator.rb
64
+ - lib/gitwrap/dependencies.rb
65
+ - lib/gitwrap/fetch.rb
66
+ - lib/gitwrap/version.rb
67
+ homepage: https://github.com/oelizondo/gitwrap
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ allowed_push_host: https://rubygems.org
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.8
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Client that connects to Github's API.
92
+ test_files: []