github-api-client 0.3.3 → 0.4.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +1 -15
  4. data/Gemfile.lock +23 -25
  5. data/NEWS +18 -0
  6. data/Rakefile +38 -0
  7. data/TODO +6 -0
  8. data/bin/api-browser.rb +12 -17
  9. data/bin/github-api-client +33 -0
  10. data/db/migrate/001_migrate_everything.rb +18 -0
  11. data/features/user_api.feature +88 -0
  12. data/github-api-client.gemspec +41 -0
  13. data/lib/github-api-client.rb +31 -9
  14. data/lib/github-api-client/browser.rb +11 -8
  15. data/lib/github-api-client/config.rb +0 -5
  16. data/lib/github-api-client/fetchers.rb +11 -0
  17. data/lib/github-api-client/fetchers/repo.rb +32 -0
  18. data/lib/github-api-client/fetchers/user.rb +49 -0
  19. data/lib/github-api-client/helpers.rb +15 -0
  20. data/lib/github-api-client/resource.rb +72 -0
  21. data/lib/github-api-client/resources/repo.rb +13 -0
  22. data/lib/github-api-client/resources/user.rb +10 -0
  23. data/lib/github-api-client/strategies/ask.rb +14 -0
  24. data/lib/github-api-client/strategies/local.rb +14 -0
  25. data/lib/github-api-client/strategies/remote.rb +14 -0
  26. data/lib/github-api-client/strategy.rb +15 -0
  27. data/lib/github-api-client/version.rb +10 -0
  28. data/new_design +4 -0
  29. metadata +62 -68
  30. data/VERSION +0 -1
  31. data/db/migrate/001_create_users.rb +0 -21
  32. data/db/migrate/002_create_user_followings.rb +0 -12
  33. data/db/migrate/003_create_repos.rb +0 -32
  34. data/db/migrate/004_create_repo_watchings.rb +0 -12
  35. data/db/migrate/005_create_organizations.rb +0 -15
  36. data/db/migrate/006_create_organizations_members.rb +0 -12
  37. data/lib/github-api-client/organization.rb +0 -64
  38. data/lib/github-api-client/repo.rb +0 -99
  39. data/lib/github-api-client/user.rb +0 -186
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ /doc/
3
+ .yardoc
4
+ *.swp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -1,17 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rainbow", ">= 1.1.3"
4
- gem "rake", "0.8.7"
5
- gem "activerecord", ">= 3.1.0"
6
- gem "activesupport", ">= 3.1.0"
7
- gem "sqlite3", ">= 1.3.5"
8
- gem "OptionParser", ">= 0.5.1"
9
-
10
- group :development do
11
- gem "rspec", ">= 2.7.0"
12
- gem "mocha", ">= 0.10.0"
13
- gem "yard", ">= 0.6.0"
14
- gem "cucumber", ">= 1.1.4"
15
- gem "jeweler", ">= 1.6.4"
16
- gem "rcov", ">= 0.9.11"
17
- end
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,19 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ github-api-client (0.4.0.pre)
5
+ OptionParser (>= 0.5.1)
6
+ activerecord (>= 3.1.0)
7
+ activesupport (>= 3.1.0)
8
+ rainbow (>= 1.1.3)
9
+ rake (= 0.8.7)
10
+ sqlite3 (>= 1.3.5)
11
+
1
12
  GEM
2
13
  remote: http://rubygems.org/
3
14
  specs:
4
15
  OptionParser (0.5.1)
5
- activemodel (3.1.3)
6
- activesupport (= 3.1.3)
16
+ activemodel (3.2.1)
17
+ activesupport (= 3.2.1)
7
18
  builder (~> 3.0.0)
8
- i18n (~> 0.6)
9
- activerecord (3.1.3)
10
- activemodel (= 3.1.3)
11
- activesupport (= 3.1.3)
12
- arel (~> 2.2.1)
19
+ activerecord (3.2.1)
20
+ activemodel (= 3.2.1)
21
+ activesupport (= 3.2.1)
22
+ arel (~> 3.0.0)
13
23
  tzinfo (~> 0.3.29)
14
- activesupport (3.1.3)
24
+ activesupport (3.2.1)
25
+ i18n (~> 0.6)
15
26
  multi_json (~> 1.0)
16
- arel (2.2.1)
27
+ arel (3.0.0)
17
28
  builder (3.0.0)
18
29
  cucumber (1.1.4)
19
30
  builder (>= 2.1.2)
@@ -22,22 +33,16 @@ GEM
22
33
  json (>= 1.4.6)
23
34
  term-ansicolor (>= 1.0.6)
24
35
  diff-lcs (1.1.3)
25
- gherkin (2.7.3)
36
+ gherkin (2.7.6)
26
37
  json (>= 1.4.6)
27
- git (1.2.5)
28
38
  i18n (0.6.0)
29
- jeweler (1.6.4)
30
- bundler (~> 1.0)
31
- git (>= 1.2.5)
32
- rake
33
39
  json (1.6.5)
34
40
  metaclass (0.0.1)
35
- mocha (0.10.2)
41
+ mocha (0.10.3)
36
42
  metaclass (~> 0.0.1)
37
43
  multi_json (1.0.4)
38
44
  rainbow (1.1.3)
39
45
  rake (0.8.7)
40
- rcov (0.9.11)
41
46
  rspec (2.8.0)
42
47
  rspec-core (~> 2.8.0)
43
48
  rspec-expectations (~> 2.8.0)
@@ -55,15 +60,8 @@ PLATFORMS
55
60
  ruby
56
61
 
57
62
  DEPENDENCIES
58
- OptionParser (>= 0.5.1)
59
- activerecord (>= 3.1.0)
60
- activesupport (>= 3.1.0)
61
63
  cucumber (>= 1.1.4)
62
- jeweler (>= 1.6.4)
64
+ github-api-client!
63
65
  mocha (>= 0.10.0)
64
- rainbow (>= 1.1.3)
65
- rake (= 0.8.7)
66
- rcov (>= 0.9.11)
67
66
  rspec (>= 2.7.0)
68
- sqlite3 (>= 1.3.5)
69
67
  yard (>= 0.6.0)
data/NEWS ADDED
@@ -0,0 +1,18 @@
1
+ github-api-client NEWS -- history of user-visible changes
2
+ updated at 2011/01/30
3
+
4
+ Version 0.4.0.pre
5
+ * This version serves the purpose of showing new features and new design that github-api-client implemented recently
6
+ * New design
7
+ focuses on splitting the logic into:
8
+ - Models (backend) - generally hidden from end-user
9
+ - Fetchers (frontend) - retrieve data from the site and store them locally using strategies
10
+ * Strategy - defines when to refresh data
11
+ - Resources (frontend) - light objects with @attributes hash and defined accessors for fields (also for editable fields)
12
+
13
+ * Resource description
14
+ classes like Repository or User are now inheriting from Resource class which generates accessor methods for them and more
15
+
16
+ * Fully dynamic models and migrations generation
17
+ taking advantage from using Resource classes to describe API resources, migrations now create tables for every resource
18
+ models also include associations defined in Resource classes
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ include Rake::DSL
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+ include Rake::DSL # supressess jeweler warnings
15
+
16
+ desc 'run irb session against this library'
17
+ task :irb do
18
+ system 'irb -I./lib -r github-api-client'
19
+ end
20
+
21
+ require 'rspec/core'
22
+ require 'rspec/core/rake_task'
23
+ RSpec::Core::RakeTask.new(:spec) do |spec|
24
+ spec.pattern = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ require 'cucumber/rake/task'
33
+ Cucumber::Rake::Task.new(:features)
34
+
35
+ task :default => :spec
36
+
37
+ require 'yard'
38
+ YARD::Rake::YardocTask.new
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ * checking how many requests are left (from http headers [caching preffered from last request])
2
+ * helper methods for fetching data
3
+ | writing GitHub::Fetchers::Repository.get(resource_user.login + '/' + resource_user.repos.select{|repo| repo.name == 'github-api-client'}) # is not fun!
4
+ | rethink design fetchers?
5
+ * helpers for choosing strategy (maybe providing short descriptions?)
6
+ * use minitest for testing with rspec matchers
data/bin/api-browser.rb CHANGED
@@ -2,22 +2,17 @@
2
2
 
3
3
  $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
4
4
 
5
- require 'github-api-client'
5
+ require 'github-api-client/resource'
6
6
 
7
- puts GitHub::Config::Version
8
-
9
- unless ARGV.include? 'test'
10
- # Dev temporary code here
11
- # GitHub::Repo.get('parndt/hub').parent.fetch(:self, :watchers).watchers
12
- org = GitHub::Organization.get('github').fetch(:members, :repositories)
13
- p org.repositories.collect {|r| r.name}
14
- p org.members.collect {|u| u.login}
15
- else # launches all-features code
16
- # Performance tests
17
- GitHub::Organization.get('rails').fetch(:repositories).repositories
18
- GitHub::Repo.get('parndt/hub').parent.fetch(:self, :watchers).watchers
19
- GitHub::Repo.get('rails/rails', :organization).fetch(:self)
20
- GitHub::User.get('kneath').fetch(:followers, :followings)
21
- GitHub::User.get('schacon').fetch(:organizations).organizations
22
- GitHub::Organization.get('github').fetch(:members, :repositories).members
7
+ class User
8
+ @@attributes = {login: String, name: String, has_repos: true, location: String}
9
+ @@pushables = [:name, :location]
10
+ @@associations = {repositories: [nil, -> { has_many :repositories, :class_name => Repo}]}
11
+ include Resource
23
12
  end
13
+
14
+ u = User.new
15
+ u.name = 'Kuba'
16
+ u.attributes[:has_repos] = true
17
+ u.save
18
+ p u.repositories
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'github-api-client'
6
+
7
+ # These are the default option values. By setting them
8
+ # before we parse the arguments, we make sure we don't have
9
+ # any missing argument wonkyness
10
+ GitHub::Config::Options[:verbose] = false
11
+ GitHub::Config::Options[:server] = 'github.com'
12
+ GitHub::Config::Options[:reset_db] = false
13
+
14
+ OptionParser.new { |opts|
15
+
16
+ opts.on( '-h', '--help', 'Display this screen' ) do
17
+ puts opts
18
+ end
19
+ opts.on( '-v', '--verbose', 'Enable Verbose Output') do
20
+ GitHub::Config::Options[:verbose] = true
21
+ end
22
+ opts.on( '-s', '--server SERVER', 'Change the GitHub server') do |host|
23
+ GitHub::Config::Options[:server] = host
24
+ end
25
+ opts.on( '-r', '--reset-db', 'Reset the database') do
26
+ GitHub::Config::Options[:reset_db] = true
27
+ end
28
+
29
+ }.parse!
30
+
31
+ GitHub::Config::Options[:reset_db] ? GitHub::Config.reset : GitHub::Config.setup
32
+
33
+ puts GitHub::Organization.get('rails').fetch(:repositories).repositories.watchers.map { |x| x.attributes }
@@ -0,0 +1,18 @@
1
+ require 'active_support/core_ext/string'
2
+
3
+ class MigrateEverything < ActiveRecord::Migration
4
+ def change
5
+ GitHub::Resources.constants.each do |resource|
6
+ klass = GitHub::Resources.const_get(resource)
7
+ create_table resource.to_s.pluralize.downcase do |table|
8
+ klass.class_variable_get(:@@attributes).each_pair do |key, value|
9
+ table.send(value, key)
10
+ end
11
+
12
+ klass.class_variable_get(:@@associations).each_pair do |key, value|
13
+ table.references value.first unless value.first.nil?
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,88 @@
1
+ Feature: User frontend
2
+ In order to use API provided by this library properly
3
+ I need to use provided set of objects
4
+
5
+ Background:
6
+ Given the "User" resource
7
+
8
+ Scenario: Existence of User class
9
+ Given I am trying to make use of this library
10
+ Then "User" resource should exist
11
+
12
+ Scenario: Existence of User resource
13
+ Given the "User" resource
14
+ Then the object should exist
15
+
16
+ Scenario: User's name
17
+ Given the "name" property
18
+ Then the property should be "Chris Wanstrath"
19
+ And the property should be writable
20
+
21
+ Scenario: User's location
22
+ Given the "location" property
23
+ Then the property should be "San Francisco"
24
+ And the property should be writable
25
+
26
+ Scenario: User's company
27
+ Given the "company" property
28
+ Then the property should be "GitHub"
29
+ And the property should be writable
30
+
31
+ Scenario: User's login
32
+ Given the "login" property
33
+ Then the property should be "defunkt"
34
+ And the property should not be writable
35
+
36
+ Scenario: User's bio
37
+ Given the "bio" property
38
+ Then the property should be "The greatest and best programmer in the world."
39
+ Then the property should be writable
40
+
41
+ Scenario: User's email
42
+ Given the "email" property
43
+ Then the property should be "chris@wanstrath.com"
44
+ And the property should be writable
45
+
46
+ Scenario: User's hireable status
47
+ Given the "hireable" property
48
+ Then the property should be true
49
+ And the property should be writable
50
+
51
+ Scenario: User's blog
52
+ Given the "blog" property
53
+ Then the property should be "http://chriswanstrath.com/"
54
+ And the property should be writable
55
+
56
+ Scenario: Saving User
57
+ Given that I am authenticated as this resource
58
+ And I am tracking browser actions
59
+ When I set "name" to "test"
60
+ And I update the resource
61
+ Then the resource changes should be cleared
62
+ And the browser fires up a PATCH request at "/user"
63
+
64
+ Scenario: Getting user's public repos
65
+ Given that I am trying to fetch user's public repos
66
+ But I am not authenticated
67
+ When I fetch resource's repositories
68
+ Then I can access resource's repositories
69
+ And accessed data should be a set of repositories
70
+
71
+ Scenario: Getting all user's repos
72
+ Given that I am trying to fetch user's repos
73
+ And I am authenticated
74
+ When I fetch resource's repositories
75
+ Then I can access resource's private repositories
76
+ And accessed data should be a set of repositories
77
+
78
+ Scenario: Getting user's followers
79
+ Given that I am trying to fetch resource's followers
80
+ When I fetch resource's followers
81
+ Then I can access resource's followers
82
+ And accessed data should be a set of users
83
+
84
+ Scenario: Getting user's followings
85
+ Given that I am trying to fetch resource's followings
86
+ When I fetch resource's followings
87
+ Then I can access resource's followings
88
+ And accessed data should be a set of users
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.unshift File.expand_path("../lib", __FILE__)
4
+ require "github-api-client/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "github-api-client"
8
+ s.version = GitHub::Version::String
9
+
10
+ s.authors = [%{Jakub Okoński}]
11
+ s.date = "2012-01-30"
12
+ s.description = "Caches retrieved information to your user profile and reuses it when you query again."
13
+ s.email = "kuba@okonski.org"
14
+ s.executables = ["api-browser.rb github-api-client"]
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md",
18
+ "TODO",
19
+ "NEWS"
20
+ ]
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+
25
+ s.homepage = %{http://github.com/farnoy/github-api-client}
26
+ s.licenses = ["MIT"]
27
+ s.require_paths = ["lib"]
28
+ s.summary = %{Library for easy GitHub API browsing}
29
+
30
+ s.add_runtime_dependency("rainbow", [">= 1.1.3"])
31
+ s.add_runtime_dependency("rake", ["= 0.8.7"])
32
+ s.add_runtime_dependency("activerecord", [">= 3.1.0"])
33
+ s.add_runtime_dependency("activesupport", [">= 3.1.0"])
34
+ s.add_runtime_dependency("sqlite3", [">= 1.3.5"])
35
+ s.add_runtime_dependency("OptionParser", [">= 0.5.1"])
36
+
37
+ s.add_development_dependency("rspec", [">= 2.7.0"])
38
+ s.add_development_dependency("mocha", [">= 0.10.0"])
39
+ s.add_development_dependency("yard", [">= 0.6.0"])
40
+ s.add_development_dependency("cucumber", [">= 1.1.4"])
41
+ end
@@ -6,12 +6,27 @@ $:.unshift File.dirname(__FILE__)
6
6
 
7
7
  require 'net/http'
8
8
  require 'uri'
9
- require 'yaml'
9
+ require 'json'
10
10
  require 'singleton'
11
11
  require 'active_record'
12
12
  require 'core_ext/habtm'
13
13
  require 'rainbow'
14
+ require 'github-api-client/version'
14
15
  require 'github-api-client/config'
16
+ require 'github-api-client/strategy'
17
+
18
+ require 'github-api-client/base'
19
+ #require 'github-api-client/user'
20
+ #require 'github-api-client/repo'
21
+ #require 'github-api-client/organization'
22
+ require 'github-api-client/browser'
23
+ require 'github-api-client/helpers'
24
+
25
+ # Resources
26
+ require 'github-api-client/resource'
27
+ Dir[File.expand_path("github-api-client/resources/*.rb", File.dirname(__FILE__))].each do |lib|
28
+ require lib
29
+ end
15
30
 
16
31
  # This hard-coded if's will be soon replaced by Option Parser
17
32
  GitHub::Config::Options[:verbose] = true if ARGV.include? '--verbose'
@@ -21,15 +36,22 @@ else
21
36
  GitHub::Config.setup
22
37
  end
23
38
 
24
- require 'github-api-client/base'
25
- require 'github-api-client/user'
26
- require 'github-api-client/repo'
27
- require 'github-api-client/organization'
28
- require 'github-api-client/browser'
39
+ # Fetchers
40
+ require 'github-api-client/fetchers'
41
+ Dir[File.expand_path("github-api-client/fetchers/*.rb", File.dirname(__FILE__))].each do |lib|
42
+ require lib
43
+ end
44
+
45
+ #unless $user = GitHub::User.where(GitHub::Config::Secrets).first
46
+ # $user = GitHub::User.create(GitHub::Config::Secrets)
47
+ #end if GitHub::Config::Secrets
48
+
29
49
 
30
- unless $user = GitHub::User.where(GitHub::Config::Secrets).first
31
- $user = GitHub::User.create(GitHub::Config::Secrets)
32
- end if GitHub::Config::Secrets
50
+ # Strategies
51
+ require 'github-api-client/strategies/ask'
52
+ require 'github-api-client/strategies/remote'
53
+ require 'github-api-client/strategies/local'
54
+ GitHub::Config::Options[:strategy] = GitHub::Strategies::Ask # GitHub::CachingStrategy
33
55
 
34
56
 
35
57
  # General placeholder for all of the GitHub API sweets