github-api-client 0.1.1 → 0.1.1.1

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.
@@ -10,10 +10,15 @@ require 'yaml'
10
10
  require 'singleton'
11
11
  require 'active_record'
12
12
 
13
- module GitHub #:nodoc:
13
+ # General placeholder for all of the GitHub API sweets
14
+ module GitHub
15
+ # Keeps all the configuration stuff
14
16
  module Config
17
+ # Constant with defined all the paths used in the application
15
18
  Path = {:dir => ENV['HOME'] + "/.github", :dbfile => ENV['HOME'] + "/.github/github.db", :migrations => Gem.loaded_specs['github-api-client'].full_gem_path + "/db/migrate", :secrets => ENV['HOME'] + "/.github" + "/secrets.yml"}
16
19
 
20
+ # Sets up the database and migrates it
21
+ # @return [nil]
17
22
  def self.setup
18
23
  Dir.mkdir GitHub::Config::Path[:dir] rescue nil
19
24
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => GitHub::Config::Path[:dbfile]
@@ -2,6 +2,7 @@ module GitHub
2
2
  # Basic functionality inherited later
3
3
  class Base
4
4
  # Sends key= value signals at object, that inherits it
5
+ # @param [Hash] options to assign for an object
5
6
  def build(options = {})
6
7
  options.each_pair do |k, v|
7
8
  self.send "#{k.to_sym}=", v
@@ -12,6 +13,7 @@ module GitHub
12
13
  # == VERY DANGEROUS AND EVIL
13
14
  # Recursively gets all* GitHub Users, takes years to fetch
14
15
  # * - all that have at least one follower
16
+ # @return nil
15
17
  def self.sync
16
18
  puts "Synchronizing local database with GitHub"
17
19
  users = GitHub::User.all
@@ -24,11 +26,13 @@ module GitHub
24
26
  #user.get
25
27
  #user.get_followers
26
28
  end
29
+ nil
27
30
  end
28
31
 
29
32
  # Converts pitfalls from GitHub API differences into normal data
33
+ # @param [Hash] attributes GitHub API retrieved attributes to be parsed
34
+ # @return [Hash] parsed attributes, fully compatibile with local db
30
35
  def self.parse_attributes(attributes)
31
- #p attributes
32
36
  {:name => :login, :username => :login, :fullname => :name, :followers => :followers_count, :repos => :public_repo_count, :created => :nil}.each do |k, v|
33
37
  unless v == :nil
34
38
  attributes[v] = attributes[k.to_s]
@@ -38,13 +42,11 @@ module GitHub
38
42
  attributes
39
43
  end
40
44
 
41
- def to_ary #:nodoc:
45
+ # ActiveRecord fix that returns attributes
46
+ # @return [Hash] Attributes of the object
47
+ def to_ary
42
48
  return self.attributes
43
49
  end
44
-
45
- def method_missing(method, *args, &block) #:nodoc:
46
- puts "Missing #{method}"
47
- end
48
50
  end
49
51
 
50
52
  # Singleton class, that is used globally
@@ -56,6 +58,9 @@ module GitHub
56
58
  # === Objects
57
59
  # * GitHub::User - recognition by key 'user'
58
60
  # More to be added soon
61
+ # @deprecated Nothing uses it, but may come handy later
62
+ # @param [String] yaml a YAML content to be parsed
63
+ # @return [GitHub::User, Array]
59
64
  def self.build_from_yaml(yaml)
60
65
  yaml = YAML::load yaml
61
66
  object = case
@@ -4,11 +4,14 @@ module GitHub
4
4
  include Singleton
5
5
 
6
6
  # Returnes root uri for GitHub API
7
+ # @return [String] Base GitHub API url for v2
7
8
  def self.base_uri
8
9
  "http://github.com/api/v2/yaml"
9
10
  end
10
11
 
11
12
  # Runs HTTP GET request at given uri
13
+ # @param [String] uri URI to be joined with base_uri and requested
14
+ # @return [String] request result
12
15
  def self.get(uri)
13
16
  uri = uri.gsub(" ","+")
14
17
  puts "Requesting #{URI.parse(self.base_uri + uri)}"
@@ -16,6 +19,8 @@ module GitHub
16
19
  end
17
20
 
18
21
  # Runs HTTP POST requests with options such as GitHub::User.auth_info
22
+ # @param [String] uri URI to be joined with base_uri and requested
23
+ # @return [String] request result
19
24
  def self.post(uri, options = {})
20
25
  uri = uri.gsub(" ","+")
21
26
  puts "Requesting #{URI.parse(self.base_uri + uri)} with options: #{options}"
@@ -6,6 +6,7 @@ module GitHub
6
6
 
7
7
  # Fetches info about current_user from GitHub
8
8
  # GitHub::User.new.build(:login => 'asd', :token => 'token').get #=> GitHub::User
9
+ # @return [GitHub::User] Chainable self object after syncing attributes with GitHub
9
10
  def get
10
11
  self.update_attributes YAML::load(GitHub::Browser.get("/user/show/#{self.login}"))['user']
11
12
  self
@@ -14,10 +15,15 @@ module GitHub
14
15
  # Static function, that gets information about GitHub::User by login.
15
16
  # === Examples
16
17
  # GitHub::User.get('defunkt') #=> GitHub::User
18
+ # @param [String] login GitHub user login to fetch
19
+ # @return [GitHub::User] Newly created, in local database user synced with github
17
20
  def self.get(login)
18
21
  return GitHub::User.find_or_create_by_login YAML::load(GitHub::Browser.get("/user/show/#{login}"))['user']
19
22
  end
20
23
 
24
+ # Searches for users in GitHub database
25
+ # @param [String] login GitHub user login to search
26
+ # @return [Array<GitHub::User>] All users that matched login
21
27
  def self.search(login)
22
28
  users = []
23
29
  YAML::load(GitHub::Browser.get("/user/search/#{login}"))['users'].each do |user|
@@ -26,11 +32,21 @@ module GitHub
26
32
  users
27
33
  end
28
34
 
29
- def set(route = [], options = {}) #:nodoc:
35
+ # Experimental function, requests POST transmission to custom path of GitHub API
36
+ # @param [Array] route Route splitted like: ['users', 'search', 'chacon']
37
+ # @param [Hash] options Options to pass with the request
38
+ # @option [Hash] options 'values[email]' => 'test@api.com'
39
+ def set(route = [], options = {})
30
40
  return GitHub::Browser.post "/#{route.join('/')}", options.merge(self.auth_info)
31
41
  end
32
42
 
33
43
  # End-user way to fetch information
44
+ # @param [Array<Symbol>] things Things to fetch for GitHub::User
45
+ # @option things [Symbol] :self Sync with GitHub Database
46
+ # @option things [Symbol] :followers Map followers from GitHub Database
47
+ # @return [GitHub::User] Chainable, updated User
48
+ # @see GitHub::User#get
49
+ # @see GitHub::User#get_followers
34
50
  def fetch(*things)
35
51
  things.each do |thing|
36
52
  case thing
@@ -42,6 +58,8 @@ module GitHub
42
58
  end
43
59
 
44
60
  # Executes when you got a real object
61
+ # @see GitHub::User#fetch
62
+ # @return GitHub::User Chainable after mapping followers association
45
63
  private
46
64
  def get_followers
47
65
  users = YAML::load(GitHub::Browser.get "/user/show/#{login}/followers")['users']
@@ -59,8 +77,10 @@ module GitHub
59
77
  self
60
78
  end
61
79
 
62
- # Returns an array with logins of GitHub::User followers
63
80
  public
81
+ # Returns an array with logins of GitHub::User followers
82
+ # @param [String] login GitHub login of which followers will be mapped
83
+ # @return [Array<GitHub::User>] Followers
64
84
  def self.get_followers(login)
65
85
  users = YAML::load(GitHub::Browser.get "/user/show/#{login}/followers")['users']
66
86
 
@@ -78,11 +98,16 @@ module GitHub
78
98
 
79
99
  # Collects information from authenticated user.
80
100
  # Used by post requests to authenticate
101
+ # @return [Hash] Collected from GitHub::User options for HTTP POST request authentication
81
102
  def auth_info
82
103
  {:login => self.login, :token => self.token}
83
104
  end
84
105
 
85
- # Experimental, sets information about GitHub::User or returns authenticated :self
106
+ # Experimental, sets information about GitHub::User or returns authenticated :self
107
+ # @param [String] login Login to which post request will be sent
108
+ # @param [Hash] options Options to include to a post request
109
+ # @option options [Hash] email 'values[email]' => 'test@api.com' - Sets user email to test@api.com if authenticated
110
+ # @return [String] Request retrieved data
86
111
  def post(login, options = {})
87
112
  if [:self, :me].include? login
88
113
  login = self.login
metadata CHANGED
@@ -6,7 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 1
8
8
  - 1
9
- version: 0.1.1
9
+ - 1
10
+ version: 0.1.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - "Jakub Oko\xC5\x84ski"
@@ -76,7 +77,7 @@ files:
76
77
  - lib/github_api/user.rb
77
78
  - db/migrate/002_create_followings.rb
78
79
  - db/migrate/001_create_users.rb
79
- has_rdoc: true
80
+ has_rdoc: false
80
81
  homepage: http://github.com/farnoy/github-api-client
81
82
  licenses: []
82
83