From 1f065e846acbe82ae429453b67e0825f1ba41d26 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 00:45:25 -0800 Subject: [PATCH 01/23] Introduce unimplemented API classes and move GitHub API into github/api --- lib/ghee/api/authorizations.rb | 3 +- lib/ghee/api/collaborators.rb | 7 +- lib/ghee/api/commit_comments.rb | 6 +- lib/ghee/api/commit_statuses.rb | 9 +- lib/ghee/api/commits.rb | 5 +- lib/ghee/api/contents.rb | 19 +--- lib/ghee/api/downloads.rb | 35 +----- lib/ghee/api/emails.rb | 8 +- lib/ghee/api/events.rb | 4 +- lib/ghee/api/followers.rb | 10 +- lib/ghee/api/forks.rb | 5 +- lib/ghee/api/gists.rb | 17 ++- lib/ghee/api/git_data.rb | 29 ++--- lib/ghee/api/hooks.rb | 14 +-- lib/ghee/api/issues.rb | 44 +++----- lib/ghee/api/keys.rb | 6 +- lib/ghee/api/labels.rb | 4 +- lib/ghee/api/members.rb | 18 +-- lib/ghee/api/milestones.rb | 11 +- lib/ghee/api/orgs.rb | 32 ++---- lib/ghee/api/pulls.rb | 19 ++-- lib/ghee/api/repos.rb | 6 +- lib/ghee/api/search.rb | 6 +- lib/ghee/api/users.rb | 34 +++--- lib/ghee/api/watchers.rb | 12 +- lib/ghee/github.rb | 31 +++++ lib/ghee/github/api/authorizations.rb | 14 +++ lib/ghee/github/api/collaborators.rb | 36 ++++++ lib/ghee/github/api/commit_comments.rb | 34 ++++++ lib/ghee/github/api/commit_statuses.rb | 35 ++++++ lib/ghee/github/api/commits.rb | 34 ++++++ lib/ghee/github/api/contents.rb | 47 ++++++++ lib/ghee/github/api/downloads.rb | 55 +++++++++ lib/ghee/github/api/emails.rb | 32 ++++++ lib/ghee/github/api/events.rb | 25 +++++ lib/ghee/github/api/followers.rb | 31 +++++ lib/ghee/github/api/forks.rb | 33 ++++++ lib/ghee/github/api/gists.rb | 84 ++++++++++++++ lib/ghee/github/api/git_data.rb | 108 ++++++++++++++++++ lib/ghee/github/api/hooks.rb | 45 ++++++++ lib/ghee/github/api/issues.rb | 150 +++++++++++++++++++++++++ lib/ghee/github/api/keys.rb | 56 +++++++++ lib/ghee/github/api/labels.rb | 37 ++++++ lib/ghee/github/api/members.rb | 44 ++++++++ lib/ghee/github/api/milestones.rb | 65 +++++++++++ lib/ghee/github/api/orgs.rb | 120 ++++++++++++++++++++ lib/ghee/github/api/pulls.rb | 49 ++++++++ lib/ghee/github/api/repos.rb | 36 ++++++ lib/ghee/github/api/search.rb | 40 +++++++ lib/ghee/github/api/users.rb | 113 +++++++++++++++++++ lib/ghee/github/api/watchers.rb | 41 +++++++ 51 files changed, 1514 insertions(+), 244 deletions(-) create mode 100644 lib/ghee/github.rb create mode 100644 lib/ghee/github/api/authorizations.rb create mode 100644 lib/ghee/github/api/collaborators.rb create mode 100644 lib/ghee/github/api/commit_comments.rb create mode 100644 lib/ghee/github/api/commit_statuses.rb create mode 100644 lib/ghee/github/api/commits.rb create mode 100644 lib/ghee/github/api/contents.rb create mode 100644 lib/ghee/github/api/downloads.rb create mode 100644 lib/ghee/github/api/emails.rb create mode 100644 lib/ghee/github/api/events.rb create mode 100644 lib/ghee/github/api/followers.rb create mode 100644 lib/ghee/github/api/forks.rb create mode 100644 lib/ghee/github/api/gists.rb create mode 100644 lib/ghee/github/api/git_data.rb create mode 100644 lib/ghee/github/api/hooks.rb create mode 100644 lib/ghee/github/api/issues.rb create mode 100644 lib/ghee/github/api/keys.rb create mode 100644 lib/ghee/github/api/labels.rb create mode 100644 lib/ghee/github/api/members.rb create mode 100644 lib/ghee/github/api/milestones.rb create mode 100644 lib/ghee/github/api/orgs.rb create mode 100644 lib/ghee/github/api/pulls.rb create mode 100644 lib/ghee/github/api/repos.rb create mode 100644 lib/ghee/github/api/search.rb create mode 100644 lib/ghee/github/api/users.rb create mode 100644 lib/ghee/github/api/watchers.rb diff --git a/lib/ghee/api/authorizations.rb b/lib/ghee/api/authorizations.rb index e7ee8aa..9c2de56 100644 --- a/lib/ghee/api/authorizations.rb +++ b/lib/ghee/api/authorizations.rb @@ -6,8 +6,7 @@ class Proxy < ::Ghee::ResourceProxy end def authorizations(number=nil) - prefix = number ? "./authorizations/#{number}" : "./authorizations" - Ghee::API::Authorizations::Proxy.new(connection, prefix) + raise NotImplemented end end end diff --git a/lib/ghee/api/collaborators.rb b/lib/ghee/api/collaborators.rb index f5eaaae..fae74e0 100644 --- a/lib/ghee/api/collaborators.rb +++ b/lib/ghee/api/collaborators.rb @@ -13,11 +13,11 @@ module Repos module Collaborators class Proxy < ::Ghee::ResourceProxy def add(member) - connection.put("#{path_prefix}/#{member}").status == 204 + raise NotImplemented end def remove(member) - connection.delete("#{path_prefix}/#{member}").status == 204 + raise NotImplemented end end end @@ -27,8 +27,7 @@ def remove(member) # class Proxy < ::Ghee::ResourceProxy def collaborators(user=nil, &block) - prefix = build_prefix user, "collaborators" - Collaborators::Proxy.new(connection, prefix, user, &block) + raise NotImplemented end end end diff --git a/lib/ghee/api/commit_comments.rb b/lib/ghee/api/commit_comments.rb index b0c787e..82c38db 100644 --- a/lib/ghee/api/commit_comments.rb +++ b/lib/ghee/api/commit_comments.rb @@ -12,15 +12,13 @@ module Repos class Proxy < ::Ghee::ResourceProxy def comments(id=nil, &block) - prefix = build_prefix id, "comments" - Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, id, &block + raise NotImplemented end end module Commits class Proxy < ::Ghee::ResourceProxy def comments(id=nil, &block) - prefix = build_prefix id, "comments" - Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, id, &block + raise NotImplemented end end module Comments diff --git a/lib/ghee/api/commit_statuses.rb b/lib/ghee/api/commit_statuses.rb index 4c7d4c5..1df0c8f 100644 --- a/lib/ghee/api/commit_statuses.rb +++ b/lib/ghee/api/commit_statuses.rb @@ -11,17 +11,12 @@ module API module Repos module Commits class Proxy < ::Ghee::ResourceProxy - undef_method "patch" - undef_method "destroy" - undef_method "create" def statuses(id=nil, &block) - prefix = build_prefix id, "statuses" - Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, id, &block + raise NotImplemented end def status(&block) - prefix = build_prefix nil, "status" - Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, id, &block + raise NotImplemented end end module Statuses diff --git a/lib/ghee/api/commits.rb b/lib/ghee/api/commits.rb index 34c4a60..cdd6abb 100644 --- a/lib/ghee/api/commits.rb +++ b/lib/ghee/api/commits.rb @@ -15,11 +15,10 @@ module Repos # class Proxy < ::Ghee::ResourceProxy def compare(base, head) - connection.get("#{path_prefix}/compare/#{base}...#{head}").body + raise NotImplemented end def commits(sha=nil, &block) - prefix = build_prefix sha, "commits" - Ghee::API::Repos::Commits::Proxy.new(connection, prefix, sha, &block) + raise NotImplemented end end diff --git a/lib/ghee/api/contents.rb b/lib/ghee/api/contents.rb index 8d31aa1..ea1acfb 100644 --- a/lib/ghee/api/contents.rb +++ b/lib/ghee/api/contents.rb @@ -16,30 +16,17 @@ module Contents class Proxy < ::Ghee::ResourceProxy attr_accessor :path def create(message, content=nil) - if content.nil? - message.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} - attributes = { path: path }.merge message - attributes[:content] = Base64.encode64 attributes[:content] - else - attributes = { - path: path, - message: message, - content: Base64.encode64(content) - } - end - connection.put(path_prefix, attributes).body + raise NotImplemented end end end class Proxy < ::Ghee::ResourceProxy def contents(path, &block) - proxy = Contents::Proxy.new connection, "#{path_prefix}/contents/#{path}", nil, &block - proxy.path = path - proxy + raise NotImplemented end def readme(&block) - Contents::Proxy.new connection, "#{path_prefix}/readme", {}, &block + raise NotImplemented end end end diff --git a/lib/ghee/api/downloads.rb b/lib/ghee/api/downloads.rb index bc68a1a..9080d29 100644 --- a/lib/ghee/api/downloads.rb +++ b/lib/ghee/api/downloads.rb @@ -3,52 +3,27 @@ module API module Downloads class Proxy < ::Ghee::ResourceProxy - # Creates + # Creates # # return json # def create(file_path, description="") - params = { - :name => File.basename(file_path), - :size => File.size(file_path), - :description => description - } - download = connection.post(path_prefix, params).body - s3 = Faraday.new(:url => download["s3_url"]) do |builder| - builder.request :multipart - builder.request :url_encoded - - builder.adapter :net_http - end - upload = { - :key => download["path"], - :acl => download["acl"], - :success_action_status => 201, - :Filename => download["name"], - :AWSAccessKeyId => download["accesskeyid"], - :Policy => download["policy"], - :Signature => download["signature"], - :"Content-Type" => download["mime_type"], - :file => Faraday::UploadIO.new(file_path, download["mime_type"]) - } - s3.post("/",upload).status == 201 - return download + raise NotImplemented end - # Destroys + # Destroys # # return boolean # def destroy - connection.delete(path_prefix).status == 204 + raise NotImplemented end end end class Proxy < ::Ghee::ResourceProxy def downloads(id=nil) - prefix = id ? "#{path_prefix}/downloads/#{id}" :"#{path_prefix}/downloads" - Ghee::API::Downloads::Proxy.new(connection, prefix) + raise NotImplemented end end end diff --git a/lib/ghee/api/emails.rb b/lib/ghee/api/emails.rb index 793da1c..56f19fd 100644 --- a/lib/ghee/api/emails.rb +++ b/lib/ghee/api/emails.rb @@ -10,19 +10,17 @@ module Emails class Proxy < ::Ghee::ResourceProxy def add(emails) - connection.post(path_prefix, emails).body + raise NotImplemented end def remove(emails) - connection.delete(path_prefix) do |req| - req.body = emails - end.status == 204 + raise NotImplemented end end end class Proxy < ::Ghee::ResourceProxy def emails - Ghee::API::Users::Emails::Proxy.new connection, "#{path_prefix}/emails" + raise NotImplemented end end end diff --git a/lib/ghee/api/events.rb b/lib/ghee/api/events.rb index ff3b2b8..f870817 100644 --- a/lib/ghee/api/events.rb +++ b/lib/ghee/api/events.rb @@ -17,9 +17,9 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def events(params={}) - return Proxy.new(connection, "./events",params) + raise NotImplemented end - + end end end diff --git a/lib/ghee/api/followers.rb b/lib/ghee/api/followers.rb index 0a78a9b..f35049d 100644 --- a/lib/ghee/api/followers.rb +++ b/lib/ghee/api/followers.rb @@ -8,19 +8,19 @@ module API module Users class Proxy < ::Ghee::ResourceProxy def followers - connection.get("#{path_prefix}/followers").body + raise NotImplemented end def following - connection.get("#{path_prefix}/following").body + raise NotImplemented end def following?(user) - connection.get("#{path_prefix}/following/#{user}").status == 204 + raise NotImplemented end def follow(user) - connection.put("#{path_prefix}/following/#{user}").status == 204 + raise NotImplemented end def follow!(user) - connection.delete("#{path_prefix}/following/#{user}").status == 204 + raise NotImplemented end end end diff --git a/lib/ghee/api/forks.rb b/lib/ghee/api/forks.rb index 83278ae..055cb84 100644 --- a/lib/ghee/api/forks.rb +++ b/lib/ghee/api/forks.rb @@ -13,8 +13,7 @@ module Repos module Forks class Proxy < ::Ghee::ResourceProxy def create(org=nil) - params = org ? {:org => org} : {} - connection.post(path_prefix, params).body + raise NotImplemented end end end @@ -24,7 +23,7 @@ def create(org=nil) # class Proxy < ::Ghee::ResourceProxy def forks(params={}) - Ghee::API::Repos::Forks::Proxy.new connection, "#{path_prefix}/forks", params + raise NotImplemented end end end diff --git a/lib/ghee/api/gists.rb b/lib/ghee/api/gists.rb index 1967f7b..08a8519 100644 --- a/lib/ghee/api/gists.rb +++ b/lib/ghee/api/gists.rb @@ -21,8 +21,7 @@ class Proxy < ::Ghee::ResourceProxy class Proxy < ::Ghee::ResourceProxy def comments(id = nil) - prefix = id ? "#{path_prefix}/comments/#{id}" : "#{path_prefix}/comments" - return Ghee::API::Gists::Comments::Proxy.new connection, prefix + raise NotImplemented end @@ -31,7 +30,7 @@ def comments(id = nil) # Returns true/false # def star - connection.put("#{path_prefix}/star").status == 204 + raise NotImplemented end # Unstar a gist @@ -39,7 +38,7 @@ def star # Returns true/false # def unstar - connection.delete("#{path_prefix}/star").status == 204 + raise NotImplemented end # Returns whether gist is starred @@ -47,7 +46,7 @@ def unstar # Returns true/false # def starred? - connection.get("#{path_prefix}/star").status == 204 + raise NotImplemented end # Get public gists @@ -55,7 +54,7 @@ def starred? # Returns json # def public - connection.get("#{path_prefix}/public").body + raise NotImplemented end # Get starred gists @@ -63,7 +62,7 @@ def public # Returns json # def starred - connection.get("#{path_prefix}/starred").body + raise NotImplemented end end @@ -75,9 +74,7 @@ def starred # Returns json # def gists(id=nil, params={}) - params = id if id.is_a?Hash - path_prefix = (!id.is_a?(Hash) and id) ? "./gists/#{id}" : './gists' - Proxy.new(connection, path_prefix,params) + raise NotImplemented end end end diff --git a/lib/ghee/api/git_data.rb b/lib/ghee/api/git_data.rb index 51fb137..f0074d7 100644 --- a/lib/ghee/api/git_data.rb +++ b/lib/ghee/api/git_data.rb @@ -18,8 +18,6 @@ module Git # module Blobs class Proxy < ::Ghee::ResourceProxy - undef_method "patch" - undef_method "destroy" end end @@ -27,8 +25,6 @@ class Proxy < ::Ghee::ResourceProxy # module Tags class Proxy < ::Ghee::ResourceProxy - undef_method "patch" - undef_method "destroy" end end @@ -36,8 +32,6 @@ class Proxy < ::Ghee::ResourceProxy # module Commits class Proxy < ::Ghee::ResourceProxy - undef_method "patch" - undef_method "destroy" end end @@ -45,8 +39,6 @@ class Proxy < ::Ghee::ResourceProxy # module Trees class Proxy < ::Ghee::ResourceProxy - undef_method "patch" - undef_method "destroy" end end @@ -62,45 +54,38 @@ class Proxy < ::Ghee::ResourceProxy # Get the blob by a provided sha # def blobs(sha=nil, params={}) - params = sha if sha.is_a?Hash - prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/blobs/#{sha}" : "#{path_prefix}/blobs" - Ghee::API::Repos::Git::Blobs::Proxy.new(connection, prefix, params) + raise NotImplemented end - + # Get a commit by the sha # def commits(sha=nil, params={}) - params = sha if sha.is_a?Hash - prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/commits/#{sha}" : "#{path_prefix}/commits" - Ghee::API::Repos::Git::Commits::Proxy.new(connection, prefix, params) + raise NotImplemented end # Get refs for the repo # def refs(ref=nil) - prefix = ref ? "#{path_prefix}/refs/#{ref}" : "#{path_prefix}/refs" - Ghee::API::Repos::Git::Refs::Proxy.new(connection, prefix) + raise NotImplemented end # Get tree by a given sha # def trees(sha=nil,params={}) - prefix = sha ? "#{path_prefix}/trees/#{sha}" : "#{path_prefix}/trees" - Ghee::API::Repos::Git::Trees::Proxy.new(connection, prefix, params) + raise NotImplemented end # Get a tag by a given sha # def tags(sha=nil) - prefix = sha ? "#{path_prefix}/tags/#{sha}" : "#{path_prefix}/tags" - Ghee::API::Repos::Git::Tags::Proxy.new(connection, prefix) + raise NotImplemented end end end class Proxy < :: Ghee::ResourceProxy def git - Ghee::API::Repos::Git::Proxy.new(connection, "#{path_prefix}/git") + raise NotImplemented end end end diff --git a/lib/ghee/api/hooks.rb b/lib/ghee/api/hooks.rb index 90abcf5..39ce651 100644 --- a/lib/ghee/api/hooks.rb +++ b/lib/ghee/api/hooks.rb @@ -14,12 +14,12 @@ module Repos module Hooks class Proxy < ::Ghee::ResourceProxy include Ghee::CUD - - # Test hook - This will trigger the hook with the - # latest push to the current repository. - # + + # Test hook - This will trigger the hook with the + # latest push to the current repository. + # def test - connection.post("#{path_prefix}/test").body + raise NotImplemented end @@ -35,9 +35,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def hooks(number=nil, params={}) - params = number if number.is_a?Hash - prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/hooks/#{number}" : "#{path_prefix}/hooks" - Ghee::API::Repos::Hooks::Proxy.new(connection, prefix, params) + raise NotImplemented end end end diff --git a/lib/ghee/api/issues.rb b/lib/ghee/api/issues.rb index e46a76e..0693bf3 100644 --- a/lib/ghee/api/issues.rb +++ b/lib/ghee/api/issues.rb @@ -10,14 +10,13 @@ module Repos module Assignees class Proxy < ::Ghee::ResourceProxy def check?(member) - connection.get("#{path_prefix}/#{member}").status == 204 + raise NotImplemented end end end class Proxy < ::Ghee::ResourceProxy def assignees - prefix = "#{path_prefix}/assignees" - Ghee::API::Repos::Assignees::Proxy.new(connection, prefix) + raise NotImplemented end end @@ -26,15 +25,11 @@ def assignees # module Issues - # API labels module handles all of the Github Issues + # API labels module handles all of the Github Issues # API endpoints # module Labels class Proxy < ::Ghee::ResourceProxy - undef_method "patch" - undef_method "destroy" - undef_method "create" - # Creates label for an issue using the authenicated user # # labels - Array of labels @@ -42,7 +37,7 @@ class Proxy < ::Ghee::ResourceProxy # return json # def add(labels) - connection.post(path_prefix,labels).body + raise NotImplemented end # Patchs and existing label @@ -50,7 +45,7 @@ def add(labels) # return json # def replace(labels) - connection.put(path_prefix, labels).body + raise NotImplemented end # Destroys label by id @@ -58,12 +53,12 @@ def replace(labels) # return boolean # def remove - connection.delete(path_prefix).status == 204 + raise NotImplemented end end end - # API Comments module handles all of the Github Issues + # API Comments module handles all of the Github Issues # API endpoints # module Comments @@ -73,9 +68,6 @@ class Proxy < ::Ghee::ResourceProxy module Events class Proxy < ::Ghee::ResourceProxy - undef_method "patch" - undef_method "destroy" - undef_method "create" end end @@ -92,7 +84,7 @@ class Proxy < ::Ghee::ResourceProxy # returns boolean # def close - connection.patch(path_prefix,:state => "closed").body["state"] == "closed" + raise NotImplemented end # Returns closed issues @@ -100,30 +92,25 @@ def close # Returns json # def closed - response = connection.get path_prefix do |req| - req.params["state"] = "closed" - end - response.body + raise NotImplemented end - # Returns issue comments for an issue or all of the comments + # Returns issue comments for an issue or all of the comments # for a repo def comments(id=nil) - prefix = id ? "#{path_prefix}/comments/#{id}" : "#{path_prefix}/comments" - Ghee::API::Repos::Issues::Comments::Proxy.new(connection,prefix) + raise NotImplemented end # Returns all of the labels for repo # def labels - Ghee::API::Repos::Issues::Labels::Proxy.new(connection, "#{path_prefix}/labels") + raise NotImplemented end # Returns issue events for a repo or issue number # def events(id=nil) - prefix = id ? "#{path_prefix}/events/#{id}" : "#{path_prefix}/events" - Ghee::API::Repos::Issues::Events::Proxy.new(connection,prefix) + raise NotImplemented end end @@ -137,10 +124,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def issues(number=nil) - prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/issues/#{number}" : "#{path_prefix}/issues" - issue = Ghee::API::Repos::Issues::Proxy.new(connection, prefix, number) - issue.repo = self - issue + raise NotImplemented end end end diff --git a/lib/ghee/api/keys.rb b/lib/ghee/api/keys.rb index ff77a4a..a15aef4 100644 --- a/lib/ghee/api/keys.rb +++ b/lib/ghee/api/keys.rb @@ -22,8 +22,7 @@ class Proxy < ::Ghee::ResourceProxy class Proxy < ::Ghee::ResourceProxy def keys(id=nil) - prefix = id ? "#{path_prefix}/keys/#{id}" : "#{path_prefix}/keys" - Ghee::API::Repos::Keys::Proxy.new connection, prefix + raise NotImplemented end end end @@ -44,8 +43,7 @@ class Proxy < ::Ghee::ResourceProxy class Proxy < ::Ghee::ResourceProxy def keys(id=nil) - prefix = id ? "#{path_prefix}/keys/#{id}" : "#{path_prefix}/keys" - Ghee::API::Users::Keys::Proxy.new connection, prefix + raise NotImplemented end end end diff --git a/lib/ghee/api/labels.rb b/lib/ghee/api/labels.rb index b3efd19..9254bde 100644 --- a/lib/ghee/api/labels.rb +++ b/lib/ghee/api/labels.rb @@ -27,9 +27,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def labels(number=nil, params={}) - params = number if number.is_a?Hash - prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/labels/#{number}" : "#{path_prefix}/labels" - Ghee::API::Repos::Labels::Proxy.new(connection, prefix, params) + raise NotImplemented end end end diff --git a/lib/ghee/api/members.rb b/lib/ghee/api/members.rb index 1cd96e7..e3c46c7 100644 --- a/lib/ghee/api/members.rb +++ b/lib/ghee/api/members.rb @@ -3,30 +3,25 @@ module API module Orgs class Proxy < ::Ghee::ResourceProxy def members(id=nil, &block) - prefix = build_prefix id, "members" - Ghee::API::Orgs::Members::Proxy.new connection, prefix, id, &block + raise NotImplemented end def public_members(id=nil, &block) - prefix = build_prefix id, "public_members" - Ghee::API::Orgs::PublicMembers::Proxy.new connection, prefix, id, &block + raise NotImplemented end end module PublicMembers class Proxy < ::Ghee::ResourceProxy def check?(username=nil) - prefix = username ? File.join(path_prefix, username) : path_prefix - connection.get(prefix).status == 204 + raise NotImplemented end def add(username=nil) - prefix = username ? File.join(path_prefix, username) : path_prefix - connection.put(prefix).status == 204 + raise NotImplemented end alias_method :publicize, :add def remove(username=nil) - prefix = username ? File.join(path_prefix, username) : path_prefix - connection.delete(prefix).status == 204 + raise NotImplemented end alias_method :conceal, :remove end @@ -34,8 +29,7 @@ def remove(username=nil) module Members class Proxy < ::Ghee::ResourceProxy def check?(username=nil) - prefix = username ? File.join(path_prefix, username) : path_prefix - connection.get(prefix).status == 204 + raise NotImplemented end end end diff --git a/lib/ghee/api/milestones.rb b/lib/ghee/api/milestones.rb index 0aceb2e..44afd9b 100644 --- a/lib/ghee/api/milestones.rb +++ b/lib/ghee/api/milestones.rb @@ -26,7 +26,7 @@ class Proxy < ::Ghee::ResourceProxy # returns boolean # def close - connection.patch(path_prefix,:state => "closed").body["state"] == "closed" + raise NotImplemented end # Returns closed milestones @@ -34,10 +34,7 @@ def close # Returns json # def closed - response = connection.get path_prefix do |req| - req.params["state"] = "closed" - end - response.body + raise NotImplemented end end @@ -53,9 +50,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def milestones(number=nil, params={}) - params = number if number.is_a?Hash - prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/milestones/#{number}" : "#{path_prefix}/milestones" - Ghee::API::Repos::Milestones::Proxy.new(connection, prefix, params) + raise NotImplemented end end end diff --git a/lib/ghee/api/orgs.rb b/lib/ghee/api/orgs.rb index 835a3fa..90dbdbe 100644 --- a/lib/ghee/api/orgs.rb +++ b/lib/ghee/api/orgs.rb @@ -25,34 +25,32 @@ module Teams # module Members - # Members::Proxy inherits from Ghee::Proxy and + # Members::Proxy inherits from Ghee::Proxy and # enables defining methods on the proxy object # class Proxy < ::Ghee::ResourceProxy def add(member) - connection.put("#{path_prefix}/#{member}").status == 204 + raise NotImplemented end def remove(member) - connection.delete("#{path_prefix}/#{member}").status == 204 + raise NotImplemented end def check?(username=nil) - prefix = username ? File.join(path_prefix, username) : path_prefix - connection.get(prefix).status == 204 + raise NotImplemented end end end - # Teams::Proxy inherits from Ghee::Proxy and + # Teams::Proxy inherits from Ghee::Proxy and # enables defining methods on the proxy object # class Proxy < ::Ghee::ResourceProxy include Ghee::CUD def members(name=nil, &block) - prefix = name ? "#{path_prefix}/members/#{name}" : "#{path_prefix}/members" - Ghee::API::Orgs::Teams::Members::Proxy.new(connection, prefix, name, &block) + raise NotImplemented end end @@ -69,8 +67,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def teams(number=nil, &block) - prefix = (!number.is_a?(Hash) and number) ? "./teams/#{number}" : "#{path_prefix}/teams" - Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, number, &block) + raise NotImplemented end # Repos for a orgs @@ -78,9 +75,7 @@ def teams(number=nil, &block) # Returns json # def repos(name=nil, &block) - params = name if name.is_a?Hash - prefix = (!name.is_a?(Hash) and name) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos" - Ghee::API::Repos::Proxy.new(connection,prefix,name, &block) + raise NotImplemented end # User Membership for an org @@ -89,8 +84,7 @@ def repos(name=nil, &block) # def memberships(user, &block) - prefix = "#{path_prefix}/memberships/#{user}" - Ghee::API::Orgs::Memberships::MembershipsProxy.new(connection, prefix, nil, &block) + raise NotImplemented end end @@ -99,11 +93,10 @@ def memberships(user, &block) # Returns json # def team(number, params={}) - prefix = "./teams/#{number}" - Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, params) + raise NotImplemented end - # Returns list of the authenticated users organizations or + # Returns list of the authenticated users organizations or # an organization by name # # org - String name of the organization (optional) @@ -111,8 +104,7 @@ def team(number, params={}) # Returns json # def orgs(name=nil, &block) - prefix = (!name.is_a?(Hash) and name) ? "./orgs/#{name}" : "user/orgs" - Proxy.new(connection, prefix, name, &block) + raise NotImplemented end end end diff --git a/lib/ghee/api/pulls.rb b/lib/ghee/api/pulls.rb index 0cc12c0..75f5147 100644 --- a/lib/ghee/api/pulls.rb +++ b/lib/ghee/api/pulls.rb @@ -15,20 +15,19 @@ class Proxy < ::Ghee::ResourceProxy include Ghee::CUD def commits - connection.get("#{path_prefix}/commits").body + raise NotImplemented end - + def files - connection.get("#{path_prefix}/files").body + raise NotImplemented end - + def merge? - connection.get("#{path_prefix}/merge").status == 204 + raise NotImplemented end - + def merge!(message=nil) - params = message ? {:commit_message=>message} : {} - connection.put("#{path_prefix}/merge", params).body + raise NotImplemented end end end @@ -38,9 +37,7 @@ def merge!(message=nil) # class Proxy < ::Ghee::ResourceProxy def pulls(number=nil, params={}) - params = number if number.is_a?Hash - prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/pulls/#{number}" : "#{path_prefix}/pulls" - Ghee::API::Repos::Pulls::Proxy.new(connection, prefix, params) + raise NotImplemented end end end diff --git a/lib/ghee/api/repos.rb b/lib/ghee/api/repos.rb index a7eb48f..76f4294 100644 --- a/lib/ghee/api/repos.rb +++ b/lib/ghee/api/repos.rb @@ -24,11 +24,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def repos(login, name = nil) - repo = name.nil? ? login : "#{login}/#{name}" - path_prefix = "./repos/#{repo}" - proxy = Proxy.new(connection, path_prefix) - proxy.repo_name = repo - proxy + raise NotImplemented end end diff --git a/lib/ghee/api/search.rb b/lib/ghee/api/search.rb index 55f04fd..445a56d 100644 --- a/lib/ghee/api/search.rb +++ b/lib/ghee/api/search.rb @@ -10,8 +10,7 @@ module Repos module Issues class Proxy < ::Ghee::ResourceProxy def search(term, state = "open") - url = "./legacy/issues/search/#{@repo.repo_name}/#{state}/#{term}" - Ghee::API::Search::Issues::Proxy.new(connection, url) + raise NotImplemented end end end @@ -27,8 +26,7 @@ class Proxy < ::Ghee::ResourceProxy end class Proxy < ::Ghee::ResourceProxy def issues(repo, term, state = "open") - url = "./legacy/issues/search/#{repo}/#{state}/#{term}" - Issues::Proxy.new(connection, url) + raise NotImplemented end end end diff --git a/lib/ghee/api/users.rb b/lib/ghee/api/users.rb index 961c22e..918ece9 100644 --- a/lib/ghee/api/users.rb +++ b/lib/ghee/api/users.rb @@ -8,13 +8,13 @@ module API module Membership class MembershipProxy < ::Ghee::ResourceProxy def admin? - self['role'] == "admin" + raise NotImplemented end def active? - self['state'] == 'active' + raise NotImplemented end def activate! - connection.patch(path_prefix, {state: "active"}).body + raise NotImplemented end end end @@ -29,19 +29,18 @@ module Users # module Memberships - # Memberships::Proxy inherits from Ghee::Proxy and + # Memberships::Proxy inherits from Ghee::Proxy and # enables defining methods on the proxy object # class Proxy < ::Ghee::ResourceProxy #Org membership for the user # - #State: string to limit scope to either active or + #State: string to limit scope to either active or #pending # #Returns json def org(name, &block) - prefix = "#{path_prefix}/#{name}" - Ghee::API::Membership::MembershipProxy.new(connection, prefix, nil, &block) + raise NotImplemented end end @@ -58,7 +57,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def gists(params={}) - Ghee::API::Gists::Proxy.new(connection,"#{path_prefix}/gists", params) + raise NotImplemented end # Repos for a user @@ -66,12 +65,10 @@ def gists(params={}) # Returns json # def repos(name=nil, params={}) - params = name if name.is_a?Hash - prefix = name.is_a?(String) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos" - Ghee::API::Repos::Proxy.new(connection,prefix, params) + raise NotImplemented end - # Returns list of the provided users organizations or + # Returns list of the provided users organizations or # an organization by name # # org - String name of the organization (optional) @@ -79,15 +76,12 @@ def repos(name=nil, params={}) # Returns json # def orgs(org=nil, params={}) - params = org if org.is_a?Hash - prefix = org.is_a?(String) ? "./orgs/#{org}" : "#{path_prefix}/orgs" - Ghee::API::Orgs::Proxy.new(connection, prefix, params) + raise NotImplemented end - # Returns a Memberships Proxy + # Returns a Memberships Proxy def memberships(params={state: "active"}, &block) - prefix = "#{path_prefix}/memberships/orgs" - Ghee::API::Users::Memberships::Proxy.new(connection, prefix, params, &block) + raise NotImplemented end end @@ -96,7 +90,7 @@ def memberships(params={state: "active"}, &block) # Returns json # def user(&block) - Proxy.new(connection, './user', nil, &block) + raise NotImplemented end # Get a single user @@ -106,7 +100,7 @@ def user(&block) # Returns json # def users(user) - Proxy.new(connection, "./users/#{user}") + raise NotImplemented end end end diff --git a/lib/ghee/api/watchers.rb b/lib/ghee/api/watchers.rb index e841a6c..3f10c54 100644 --- a/lib/ghee/api/watchers.rb +++ b/lib/ghee/api/watchers.rb @@ -14,25 +14,25 @@ module Repos # enables defining methods on the proxy object # class Proxy < ::Ghee::ResourceProxy - + def watchers - connection.get("#{path_prefix}/watchers").body + raise NotImplemented end end end module Users class Proxy < ::Ghee::ResourceProxy def watched - connection.get("#{path_prefix}/watched").body + raise NotImplemented end def watching?(user,repo) - connection.get("#{path_prefix}/watched/#{user}/#{repo}").status == 204 + raise NotImplemented end def watch(user, repo) - connection.put("#{path_prefix}/watched/#{user}/#{repo}").status == 204 + raise NotImplemented end def watch!(user, repo) - connection.delete("#{path_prefix}/watched/#{user}/#{repo}").status == 204 + raise NotImplemented end end end diff --git a/lib/ghee/github.rb b/lib/ghee/github.rb new file mode 100644 index 0000000..eedbe9f --- /dev/null +++ b/lib/ghee/github.rb @@ -0,0 +1,31 @@ +class Ghee + module GitHub + module API + end + end +end + +require 'ghee/github/api/authorizations' +require 'ghee/github/api/gists' +require 'ghee/github/api/users' +require 'ghee/github/api/events' +require 'ghee/github/api/repos' +require 'ghee/github/api/issues' +require 'ghee/github/api/milestones' +require 'ghee/github/api/orgs' +require 'ghee/github/api/git_data' +require 'ghee/github/api/labels' +require 'ghee/github/api/hooks' +require 'ghee/github/api/collaborators' +require 'ghee/github/api/forks' +require 'ghee/github/api/commits' +require 'ghee/github/api/commit_comments' +require 'ghee/github/api/commit_statuses' +require 'ghee/github/api/keys' +require 'ghee/github/api/watchers' +require 'ghee/github/api/emails' +require 'ghee/github/api/followers' +require 'ghee/github/api/pulls' +require 'ghee/github/api/search' +require 'ghee/github/api/contents' +require 'ghee/github/api/members' diff --git a/lib/ghee/github/api/authorizations.rb b/lib/ghee/github/api/authorizations.rb new file mode 100644 index 0000000..e7ee8aa --- /dev/null +++ b/lib/ghee/github/api/authorizations.rb @@ -0,0 +1,14 @@ +class Ghee + module API + module Authorizations + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + end + + def authorizations(number=nil) + prefix = number ? "./authorizations/#{number}" : "./authorizations" + Ghee::API::Authorizations::Proxy.new(connection, prefix) + end + end + end +end diff --git a/lib/ghee/github/api/collaborators.rb b/lib/ghee/github/api/collaborators.rb new file mode 100644 index 0000000..f5eaaae --- /dev/null +++ b/lib/ghee/github/api/collaborators.rb @@ -0,0 +1,36 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + module Collaborators + class Proxy < ::Ghee::ResourceProxy + def add(member) + connection.put("#{path_prefix}/#{member}").status == 204 + end + + def remove(member) + connection.delete("#{path_prefix}/#{member}").status == 204 + end + end + end + + # Repos::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + def collaborators(user=nil, &block) + prefix = build_prefix user, "collaborators" + Collaborators::Proxy.new(connection, prefix, user, &block) + end + end + end + end +end diff --git a/lib/ghee/github/api/commit_comments.rb b/lib/ghee/github/api/commit_comments.rb new file mode 100644 index 0000000..b0c787e --- /dev/null +++ b/lib/ghee/github/api/commit_comments.rb @@ -0,0 +1,34 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + class Proxy < ::Ghee::ResourceProxy + + def comments(id=nil, &block) + prefix = build_prefix id, "comments" + Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, id, &block + end + end + module Commits + class Proxy < ::Ghee::ResourceProxy + def comments(id=nil, &block) + prefix = build_prefix id, "comments" + Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, id, &block + end + end + module Comments + class Proxy < ::Ghee::ResourceProxy + end + end + end + end + end +end + diff --git a/lib/ghee/github/api/commit_statuses.rb b/lib/ghee/github/api/commit_statuses.rb new file mode 100644 index 0000000..4c7d4c5 --- /dev/null +++ b/lib/ghee/github/api/commit_statuses.rb @@ -0,0 +1,35 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + module Commits + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + undef_method "create" + + def statuses(id=nil, &block) + prefix = build_prefix id, "statuses" + Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, id, &block + end + def status(&block) + prefix = build_prefix nil, "status" + Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, id, &block + end + end + module Statuses + class Proxy < ::Ghee::ResourceProxy + end + end + end + end + end +end + diff --git a/lib/ghee/github/api/commits.rb b/lib/ghee/github/api/commits.rb new file mode 100644 index 0000000..34c4a60 --- /dev/null +++ b/lib/ghee/github/api/commits.rb @@ -0,0 +1,34 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + # Repos::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + def compare(base, head) + connection.get("#{path_prefix}/compare/#{base}...#{head}").body + end + def commits(sha=nil, &block) + prefix = build_prefix sha, "commits" + Ghee::API::Repos::Commits::Proxy.new(connection, prefix, sha, &block) + end + end + + module Commits + class Proxy < ::Ghee::ResourceProxy + end + end + end + end +end + + diff --git a/lib/ghee/github/api/contents.rb b/lib/ghee/github/api/contents.rb new file mode 100644 index 0000000..5303b80 --- /dev/null +++ b/lib/ghee/github/api/contents.rb @@ -0,0 +1,47 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + # The Contents module handles all of the Github repos file contents + # API endpoints + # + module Contents + class Proxy < ::Ghee::ResourceProxy + attr_accessor :path + def create(message, content=nil) + if content.nil? + message.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} + attributes = { path: path }.merge message + attributes[:content] = Base64.encode64 attributes[:content] + else + attributes = { + path: path, + message: message, + content: Base64.encode64(content) + } + end + connection.put(path_prefix, attributes).body + end + end + end + + class Proxy < ::Ghee::ResourceProxy + def contents(path, &block) + proxy = Contents::Proxy.new connection, "#{path_prefix}/contents/#{path}", nil, &block + proxy.path = path + proxy + end + def readme(&block) + Contents::Proxy.new connection, "#{path_prefix}/readme", {}, &block + end + end + end + end +end diff --git a/lib/ghee/github/api/downloads.rb b/lib/ghee/github/api/downloads.rb new file mode 100644 index 0000000..bc68a1a --- /dev/null +++ b/lib/ghee/github/api/downloads.rb @@ -0,0 +1,55 @@ +class Ghee + module API + module Downloads + class Proxy < ::Ghee::ResourceProxy + + # Creates + # + # return json + # + def create(file_path, description="") + params = { + :name => File.basename(file_path), + :size => File.size(file_path), + :description => description + } + download = connection.post(path_prefix, params).body + s3 = Faraday.new(:url => download["s3_url"]) do |builder| + builder.request :multipart + builder.request :url_encoded + + builder.adapter :net_http + end + upload = { + :key => download["path"], + :acl => download["acl"], + :success_action_status => 201, + :Filename => download["name"], + :AWSAccessKeyId => download["accesskeyid"], + :Policy => download["policy"], + :Signature => download["signature"], + :"Content-Type" => download["mime_type"], + :file => Faraday::UploadIO.new(file_path, download["mime_type"]) + } + s3.post("/",upload).status == 201 + return download + end + + # Destroys + # + # return boolean + # + def destroy + connection.delete(path_prefix).status == 204 + end + end + end + + class Proxy < ::Ghee::ResourceProxy + def downloads(id=nil) + prefix = id ? "#{path_prefix}/downloads/#{id}" :"#{path_prefix}/downloads" + Ghee::API::Downloads::Proxy.new(connection, prefix) + end + end + end +end diff --git a/lib/ghee/github/api/emails.rb b/lib/ghee/github/api/emails.rb new file mode 100644 index 0000000..793da1c --- /dev/null +++ b/lib/ghee/github/api/emails.rb @@ -0,0 +1,32 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + module Users + module Emails + class Proxy < ::Ghee::ResourceProxy + + def add(emails) + connection.post(path_prefix, emails).body + end + + def remove(emails) + connection.delete(path_prefix) do |req| + req.body = emails + end.status == 204 + end + end + end + class Proxy < ::Ghee::ResourceProxy + def emails + Ghee::API::Users::Emails::Proxy.new connection, "#{path_prefix}/emails" + end + end + end + end +end + + diff --git a/lib/ghee/github/api/events.rb b/lib/ghee/github/api/events.rb new file mode 100644 index 0000000..ff3b2b8 --- /dev/null +++ b/lib/ghee/github/api/events.rb @@ -0,0 +1,25 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Events module handles all of the Github Event + # API endpoints + # + module Events + class Proxy < ::Ghee::ResourceProxy + end + + # Get events + # + # Returns json + # + def events(params={}) + return Proxy.new(connection, "./events",params) + end + + end + end +end diff --git a/lib/ghee/github/api/followers.rb b/lib/ghee/github/api/followers.rb new file mode 100644 index 0000000..0a78a9b --- /dev/null +++ b/lib/ghee/github/api/followers.rb @@ -0,0 +1,31 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + module Users + class Proxy < ::Ghee::ResourceProxy + def followers + connection.get("#{path_prefix}/followers").body + end + def following + connection.get("#{path_prefix}/following").body + end + def following?(user) + connection.get("#{path_prefix}/following/#{user}").status == 204 + end + def follow(user) + connection.put("#{path_prefix}/following/#{user}").status == 204 + end + def follow!(user) + connection.delete("#{path_prefix}/following/#{user}").status == 204 + end + end + end + end +end + + + diff --git a/lib/ghee/github/api/forks.rb b/lib/ghee/github/api/forks.rb new file mode 100644 index 0000000..83278ae --- /dev/null +++ b/lib/ghee/github/api/forks.rb @@ -0,0 +1,33 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + module Forks + class Proxy < ::Ghee::ResourceProxy + def create(org=nil) + params = org ? {:org => org} : {} + connection.post(path_prefix, params).body + end + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + def forks(params={}) + Ghee::API::Repos::Forks::Proxy.new connection, "#{path_prefix}/forks", params + end + end + end + end +end + diff --git a/lib/ghee/github/api/gists.rb b/lib/ghee/github/api/gists.rb new file mode 100644 index 0000000..1967f7b --- /dev/null +++ b/lib/ghee/github/api/gists.rb @@ -0,0 +1,84 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Gists module handles all of the Github Gist + # API endpoints + # + module Gists + + module Comments + class Proxy < ::Ghee::ResourceProxy + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + def comments(id = nil) + prefix = id ? "#{path_prefix}/comments/#{id}" : "#{path_prefix}/comments" + return Ghee::API::Gists::Comments::Proxy.new connection, prefix + end + + + # Star a gist + # + # Returns true/false + # + def star + connection.put("#{path_prefix}/star").status == 204 + end + + # Unstar a gist + # + # Returns true/false + # + def unstar + connection.delete("#{path_prefix}/star").status == 204 + end + + # Returns whether gist is starred + # + # Returns true/false + # + def starred? + connection.get("#{path_prefix}/star").status == 204 + end + + # Get public gists + # + # Returns json + # + def public + connection.get("#{path_prefix}/public").body + end + + # Get starred gists + # + # Returns json + # + def starred + connection.get("#{path_prefix}/starred").body + end + + end + + # Get gists + # + # id - String of gist id + # + # Returns json + # + def gists(id=nil, params={}) + params = id if id.is_a?Hash + path_prefix = (!id.is_a?(Hash) and id) ? "./gists/#{id}" : './gists' + Proxy.new(connection, path_prefix,params) + end + end + end +end diff --git a/lib/ghee/github/api/git_data.rb b/lib/ghee/github/api/git_data.rb new file mode 100644 index 0000000..51fb137 --- /dev/null +++ b/lib/ghee/github/api/git_data.rb @@ -0,0 +1,108 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + # The Git module handles all of the raw git data endpoints + # + module Git + + # The Blobs module handles all of the blob methods + # + module Blobs + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + end + end + + # The Tags module handles all of the tag methods + # + module Tags + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + end + end + + # The Commits module handles all of the commit methods + # + module Commits + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + end + end + + # The Trees module handles all of the commit methods + # + module Trees + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + end + end + + # The Refs module handles all of the commit methods + # + module Refs + class Proxy < ::Ghee::ResourceProxy + end + end + + class Proxy < ::Ghee::ResourceProxy + + # Get the blob by a provided sha + # + def blobs(sha=nil, params={}) + params = sha if sha.is_a?Hash + prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/blobs/#{sha}" : "#{path_prefix}/blobs" + Ghee::API::Repos::Git::Blobs::Proxy.new(connection, prefix, params) + end + + # Get a commit by the sha + # + def commits(sha=nil, params={}) + params = sha if sha.is_a?Hash + prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/commits/#{sha}" : "#{path_prefix}/commits" + Ghee::API::Repos::Git::Commits::Proxy.new(connection, prefix, params) + end + + # Get refs for the repo + # + def refs(ref=nil) + prefix = ref ? "#{path_prefix}/refs/#{ref}" : "#{path_prefix}/refs" + Ghee::API::Repos::Git::Refs::Proxy.new(connection, prefix) + end + + # Get tree by a given sha + # + def trees(sha=nil,params={}) + prefix = sha ? "#{path_prefix}/trees/#{sha}" : "#{path_prefix}/trees" + Ghee::API::Repos::Git::Trees::Proxy.new(connection, prefix, params) + end + + # Get a tag by a given sha + # + def tags(sha=nil) + prefix = sha ? "#{path_prefix}/tags/#{sha}" : "#{path_prefix}/tags" + Ghee::API::Repos::Git::Tags::Proxy.new(connection, prefix) + end + end + end + class Proxy < :: Ghee::ResourceProxy + + def git + Ghee::API::Repos::Git::Proxy.new(connection, "#{path_prefix}/git") + end + end + end + end +end diff --git a/lib/ghee/github/api/hooks.rb b/lib/ghee/github/api/hooks.rb new file mode 100644 index 0000000..90abcf5 --- /dev/null +++ b/lib/ghee/github/api/hooks.rb @@ -0,0 +1,45 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + + module Hooks + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + # Test hook - This will trigger the hook with the + # latest push to the current repository. + # + def test + connection.post("#{path_prefix}/test").body + end + + + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + # Get hooks + # + # Returns json + # + def hooks(number=nil, params={}) + params = number if number.is_a?Hash + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/hooks/#{number}" : "#{path_prefix}/hooks" + Ghee::API::Repos::Hooks::Proxy.new(connection, prefix, params) + end + end + end + end +end diff --git a/lib/ghee/github/api/issues.rb b/lib/ghee/github/api/issues.rb new file mode 100644 index 0000000..e46a76e --- /dev/null +++ b/lib/ghee/github/api/issues.rb @@ -0,0 +1,150 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + module Repos + + module Assignees + class Proxy < ::Ghee::ResourceProxy + def check?(member) + connection.get("#{path_prefix}/#{member}").status == 204 + end + end + end + class Proxy < ::Ghee::ResourceProxy + def assignees + prefix = "#{path_prefix}/assignees" + Ghee::API::Repos::Assignees::Proxy.new(connection, prefix) + end + end + + # The Issues module handles all of the Github Repo Issues + # API endpoints + # + module Issues + + # API labels module handles all of the Github Issues + # API endpoints + # + module Labels + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + undef_method "create" + + # Creates label for an issue using the authenicated user + # + # labels - Array of labels + # + # return json + # + def add(labels) + connection.post(path_prefix,labels).body + end + + # Patchs and existing label + # + # return json + # + def replace(labels) + connection.put(path_prefix, labels).body + end + + # Destroys label by id + # + # return boolean + # + def remove + connection.delete(path_prefix).status == 204 + end + end + end + + # API Comments module handles all of the Github Issues + # API endpoints + # + module Comments + class Proxy < ::Ghee::ResourceProxy + end + end + + module Events + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + undef_method "create" + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + attr_accessor :repo + + # Close issue - closed issue by id + # + # usage - ghee.repos("my_repo").issues(1).close + # + # returns boolean + # + def close + connection.patch(path_prefix,:state => "closed").body["state"] == "closed" + end + + # Returns closed issues + # + # Returns json + # + def closed + response = connection.get path_prefix do |req| + req.params["state"] = "closed" + end + response.body + end + + # Returns issue comments for an issue or all of the comments + # for a repo + def comments(id=nil) + prefix = id ? "#{path_prefix}/comments/#{id}" : "#{path_prefix}/comments" + Ghee::API::Repos::Issues::Comments::Proxy.new(connection,prefix) + end + + # Returns all of the labels for repo + # + def labels + Ghee::API::Repos::Issues::Labels::Proxy.new(connection, "#{path_prefix}/labels") + end + + # Returns issue events for a repo or issue number + # + def events(id=nil) + prefix = id ? "#{path_prefix}/events/#{id}" : "#{path_prefix}/events" + Ghee::API::Repos::Issues::Events::Proxy.new(connection,prefix) + end + + end + end + + class Proxy < ::Ghee::ResourceProxy + + + # Get issues + # + # Returns json + # + def issues(number=nil) + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/issues/#{number}" : "#{path_prefix}/issues" + issue = Ghee::API::Repos::Issues::Proxy.new(connection, prefix, number) + issue.repo = self + issue + end + end + end + end +end + + diff --git a/lib/ghee/github/api/keys.rb b/lib/ghee/github/api/keys.rb new file mode 100644 index 0000000..ff77a4a --- /dev/null +++ b/lib/ghee/github/api/keys.rb @@ -0,0 +1,56 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + module Keys + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + end + end + + # Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + def keys(id=nil) + prefix = id ? "#{path_prefix}/keys/#{id}" : "#{path_prefix}/keys" + Ghee::API::Repos::Keys::Proxy.new connection, prefix + end + end + end + # The Users module handles all of the Github Repo + # API endpoints + # + module Users + + module Keys + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + end + end + + # Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + def keys(id=nil) + prefix = id ? "#{path_prefix}/keys/#{id}" : "#{path_prefix}/keys" + Ghee::API::Users::Keys::Proxy.new connection, prefix + end + end + end + end +end + + + diff --git a/lib/ghee/github/api/labels.rb b/lib/ghee/github/api/labels.rb new file mode 100644 index 0000000..b3efd19 --- /dev/null +++ b/lib/ghee/github/api/labels.rb @@ -0,0 +1,37 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + module Labels + class Proxy < ::Ghee::ResourceProxy + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + # Get labels for a repo + # + # id - Number get a specific label (optional) + # + # Returns json + # + def labels(number=nil, params={}) + params = number if number.is_a?Hash + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/labels/#{number}" : "#{path_prefix}/labels" + Ghee::API::Repos::Labels::Proxy.new(connection, prefix, params) + end + end + end + end +end diff --git a/lib/ghee/github/api/members.rb b/lib/ghee/github/api/members.rb new file mode 100644 index 0000000..1cd96e7 --- /dev/null +++ b/lib/ghee/github/api/members.rb @@ -0,0 +1,44 @@ +class Ghee + module API + module Orgs + class Proxy < ::Ghee::ResourceProxy + def members(id=nil, &block) + prefix = build_prefix id, "members" + Ghee::API::Orgs::Members::Proxy.new connection, prefix, id, &block + end + def public_members(id=nil, &block) + prefix = build_prefix id, "public_members" + Ghee::API::Orgs::PublicMembers::Proxy.new connection, prefix, id, &block + end + end + module PublicMembers + class Proxy < ::Ghee::ResourceProxy + def check?(username=nil) + prefix = username ? File.join(path_prefix, username) : path_prefix + connection.get(prefix).status == 204 + end + + def add(username=nil) + prefix = username ? File.join(path_prefix, username) : path_prefix + connection.put(prefix).status == 204 + end + alias_method :publicize, :add + + def remove(username=nil) + prefix = username ? File.join(path_prefix, username) : path_prefix + connection.delete(prefix).status == 204 + end + alias_method :conceal, :remove + end + end + module Members + class Proxy < ::Ghee::ResourceProxy + def check?(username=nil) + prefix = username ? File.join(path_prefix, username) : path_prefix + connection.get(prefix).status == 204 + end + end + end + end + end +end diff --git a/lib/ghee/github/api/milestones.rb b/lib/ghee/github/api/milestones.rb new file mode 100644 index 0000000..0aceb2e --- /dev/null +++ b/lib/ghee/github/api/milestones.rb @@ -0,0 +1,65 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + module Repos + + # The Milestones module handles all of the Github Repo Milestones + # API endpoints + # + module Milestones + + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + # Close milestone - closed milestone by id + # + # usage - ghee.repos("my_repo").milestones(1).close + # + # returns boolean + # + def close + connection.patch(path_prefix,:state => "closed").body["state"] == "closed" + end + + # Returns closed milestones + # + # Returns json + # + def closed + response = connection.get path_prefix do |req| + req.params["state"] = "closed" + end + response.body + end + + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + # Get milestones + # + # Returns json + # + def milestones(number=nil, params={}) + params = number if number.is_a?Hash + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/milestones/#{number}" : "#{path_prefix}/milestones" + Ghee::API::Repos::Milestones::Proxy.new(connection, prefix, params) + end + end + end + end +end + + diff --git a/lib/ghee/github/api/orgs.rb b/lib/ghee/github/api/orgs.rb new file mode 100644 index 0000000..835a3fa --- /dev/null +++ b/lib/ghee/github/api/orgs.rb @@ -0,0 +1,120 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Orgs module handles all of the Github Organization + # API endpoints + # + module Orgs + + module Memberships + class MembershipsProxy < ::Ghee::ResourceProxy + end + end + + # Orgs::Teams module handles all of the Github Organization Teams + # API endpoints + # + module Teams + + # Orgs::Teams::Members module handles all of the Github Organization Teams members + # API endpoints + # + module Members + + # Members::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + def add(member) + connection.put("#{path_prefix}/#{member}").status == 204 + end + + def remove(member) + connection.delete("#{path_prefix}/#{member}").status == 204 + end + def check?(username=nil) + prefix = username ? File.join(path_prefix, username) : path_prefix + connection.get(prefix).status == 204 + end + end + end + + # Teams::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + def members(name=nil, &block) + prefix = name ? "#{path_prefix}/members/#{name}" : "#{path_prefix}/members" + Ghee::API::Orgs::Teams::Members::Proxy.new(connection, prefix, name, &block) + end + + end + end + + # Orgs::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + # Teams for an org + # + # Returns json + # + def teams(number=nil, &block) + prefix = (!number.is_a?(Hash) and number) ? "./teams/#{number}" : "#{path_prefix}/teams" + Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, number, &block) + end + + # Repos for a orgs + # + # Returns json + # + def repos(name=nil, &block) + params = name if name.is_a?Hash + prefix = (!name.is_a?(Hash) and name) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos" + Ghee::API::Repos::Proxy.new(connection,prefix,name, &block) + end + + # User Membership for an org + # + # Returns json + # + + def memberships(user, &block) + prefix = "#{path_prefix}/memberships/#{user}" + Ghee::API::Orgs::Memberships::MembershipsProxy.new(connection, prefix, nil, &block) + end + end + + # Team by id + # + # Returns json + # + def team(number, params={}) + prefix = "./teams/#{number}" + Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, params) + end + + # Returns list of the authenticated users organizations or + # an organization by name + # + # org - String name of the organization (optional) + # + # Returns json + # + def orgs(name=nil, &block) + prefix = (!name.is_a?(Hash) and name) ? "./orgs/#{name}" : "user/orgs" + Proxy.new(connection, prefix, name, &block) + end + end + end +end + diff --git a/lib/ghee/github/api/pulls.rb b/lib/ghee/github/api/pulls.rb new file mode 100644 index 0000000..0cc12c0 --- /dev/null +++ b/lib/ghee/github/api/pulls.rb @@ -0,0 +1,49 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + module Pulls + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + def commits + connection.get("#{path_prefix}/commits").body + end + + def files + connection.get("#{path_prefix}/files").body + end + + def merge? + connection.get("#{path_prefix}/merge").status == 204 + end + + def merge!(message=nil) + params = message ? {:commit_message=>message} : {} + connection.put("#{path_prefix}/merge", params).body + end + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + def pulls(number=nil, params={}) + params = number if number.is_a?Hash + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/pulls/#{number}" : "#{path_prefix}/pulls" + Ghee::API::Repos::Pulls::Proxy.new(connection, prefix, params) + end + end + end + end +end + diff --git a/lib/ghee/github/api/repos.rb b/lib/ghee/github/api/repos.rb new file mode 100644 index 0000000..a7eb48f --- /dev/null +++ b/lib/ghee/github/api/repos.rb @@ -0,0 +1,36 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + attr_accessor :repo_name + end + + # Get repos + # + # name - String of the name of the repo + # + # Returns json + # + def repos(login, name = nil) + repo = name.nil? ? login : "#{login}/#{name}" + path_prefix = "./repos/#{repo}" + proxy = Proxy.new(connection, path_prefix) + proxy.repo_name = repo + proxy + end + + end + end +end diff --git a/lib/ghee/github/api/search.rb b/lib/ghee/github/api/search.rb new file mode 100644 index 0000000..55f04fd --- /dev/null +++ b/lib/ghee/github/api/search.rb @@ -0,0 +1,40 @@ + +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + module Repos + module Issues + class Proxy < ::Ghee::ResourceProxy + def search(term, state = "open") + url = "./legacy/issues/search/#{@repo.repo_name}/#{state}/#{term}" + Ghee::API::Search::Issues::Proxy.new(connection, url) + end + end + end + end + + # The Search module handles all of the Github Search + # API endpoints + # + module Search + module Issues + class Proxy < ::Ghee::ResourceProxy + end + end + class Proxy < ::Ghee::ResourceProxy + def issues(repo, term, state = "open") + url = "./legacy/issues/search/#{repo}/#{state}/#{term}" + Issues::Proxy.new(connection, url) + end + end + end + end + + def search + API::Search::Proxy.new(connection,"") + end +end diff --git a/lib/ghee/github/api/users.rb b/lib/ghee/github/api/users.rb new file mode 100644 index 0000000..961c22e --- /dev/null +++ b/lib/ghee/github/api/users.rb @@ -0,0 +1,113 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + module Membership + class MembershipProxy < ::Ghee::ResourceProxy + def admin? + self['role'] == "admin" + end + def active? + self['state'] == 'active' + end + def activate! + connection.patch(path_prefix, {state: "active"}).body + end + end + end + + # The Users module handles all of the Github User + # API endpoints + # + module Users + + #Users::Memberships modules handles a users memberships + # + # + module Memberships + + # Memberships::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + #Org membership for the user + # + #State: string to limit scope to either active or + #pending + # + #Returns json + def org(name, &block) + prefix = "#{path_prefix}/#{name}" + Ghee::API::Membership::MembershipProxy.new(connection, prefix, nil, &block) + end + + end + end + + # Users::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + # Gists for a user + # + # Returns json + # + def gists(params={}) + Ghee::API::Gists::Proxy.new(connection,"#{path_prefix}/gists", params) + end + + # Repos for a user + # + # Returns json + # + def repos(name=nil, params={}) + params = name if name.is_a?Hash + prefix = name.is_a?(String) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos" + Ghee::API::Repos::Proxy.new(connection,prefix, params) + end + + # Returns list of the provided users organizations or + # an organization by name + # + # org - String name of the organization (optional) + # + # Returns json + # + def orgs(org=nil, params={}) + params = org if org.is_a?Hash + prefix = org.is_a?(String) ? "./orgs/#{org}" : "#{path_prefix}/orgs" + Ghee::API::Orgs::Proxy.new(connection, prefix, params) + end + + # Returns a Memberships Proxy + def memberships(params={state: "active"}, &block) + prefix = "#{path_prefix}/memberships/orgs" + Ghee::API::Users::Memberships::Proxy.new(connection, prefix, params, &block) + end + end + + # Get authenticated user + # + # Returns json + # + def user(&block) + Proxy.new(connection, './user', nil, &block) + end + + # Get a single user + # + # user - String of user login + # + # Returns json + # + def users(user) + Proxy.new(connection, "./users/#{user}") + end + end + end +end diff --git a/lib/ghee/github/api/watchers.rb b/lib/ghee/github/api/watchers.rb new file mode 100644 index 0000000..e841a6c --- /dev/null +++ b/lib/ghee/github/api/watchers.rb @@ -0,0 +1,41 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + # Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + def watchers + connection.get("#{path_prefix}/watchers").body + end + end + end + module Users + class Proxy < ::Ghee::ResourceProxy + def watched + connection.get("#{path_prefix}/watched").body + end + def watching?(user,repo) + connection.get("#{path_prefix}/watched/#{user}/#{repo}").status == 204 + end + def watch(user, repo) + connection.put("#{path_prefix}/watched/#{user}/#{repo}").status == 204 + end + def watch!(user, repo) + connection.delete("#{path_prefix}/watched/#{user}/#{repo}").status == 204 + end + end + end + end +end + From 9a48ce1721fc924423566813fc801dca8cfc4cb0 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 01:29:01 -0800 Subject: [PATCH 02/23] Abstract more GitHub/GitLab code and create ApiTranslator class --- lib/ghee.rb | 21 +--------- lib/ghee/api_translator.rb | 13 ++++++ lib/ghee/connection.rb | 10 +++-- lib/ghee/github.rb | 18 +++++++++ lib/ghee/gitlab.rb | 40 +++++++++++++++++++ lib/ghee/gitlab/api/repos.rb | 35 ++++++++++++++++ .../gitlab/translators/repo_translator.rb | 24 +++++++++++ lib/ghee/resource_proxy.rb | 30 +++++++++----- 8 files changed, 159 insertions(+), 32 deletions(-) create mode 100644 lib/ghee/api_translator.rb create mode 100644 lib/ghee/gitlab.rb create mode 100644 lib/ghee/gitlab/api/repos.rb create mode 100644 lib/ghee/gitlab/translators/repo_translator.rb diff --git a/lib/ghee.rb b/lib/ghee.rb index acb7f9a..415ec55 100644 --- a/lib/ghee.rb +++ b/lib/ghee.rb @@ -5,6 +5,7 @@ require 'ghee/uri_escape' require 'ghee/state_methods' require 'ghee/resource_proxy' +require 'ghee/api_translator' require 'ghee/api/authorizations' require 'ghee/api/gists' require 'ghee/api/users' @@ -48,7 +49,7 @@ class Ghee def initialize(options = {}, &block) @options = options @block = block if block - return @connection = Ghee::Connection.new(options, &block) + return @connection = Ghee::Connection.new(options, &block) end def in_parallel(adapter = :typhoeus, &block) @@ -58,22 +59,4 @@ def in_parallel(adapter = :typhoeus, &block) block.call ghee end end - - def self.basic_auth(user_name, password, api_url = nil) - options = { :basic_auth => {:user_name => user_name, :password => password} } - options[:api_url] = api_url if api_url - Ghee.new options - end - - def self.access_token(token, api_url = nil) - options = { :access_token => token } - options[:api_url] = api_url if api_url - Ghee.new options - end - - def self.create_token(user_name, password, scopes, api_url = nil) - auth = Ghee.basic_auth(user_name, password, api_url).authorizations.create({ - :scopes => scopes}) - auth["token"] - end end diff --git a/lib/ghee/api_translator.rb b/lib/ghee/api_translator.rb new file mode 100644 index 0000000..3c81a88 --- /dev/null +++ b/lib/ghee/api_translator.rb @@ -0,0 +1,13 @@ +class Ghee + class ApiTranslator + attr_accessor :context + + def initialize(context) + @context = context + end + + def translate_data(data) + raise NotImplemented + end + end +end diff --git a/lib/ghee/connection.rb b/lib/ghee/connection.rb index 37d72f3..8bc5e53 100644 --- a/lib/ghee/connection.rb +++ b/lib/ghee/connection.rb @@ -4,7 +4,7 @@ class Ghee class Connection < Faraday::Connection - attr_reader :hash + attr_reader :hash, :enable_url_escape, :api_url def parallel_connection(adapter=:typhoeus) conn = self.class.new @hash @@ -16,16 +16,18 @@ def parallel_connection(adapter=:typhoeus) # for authenticated access # # OAuth2 expects - # :access_token => "OAuth Token" + # :access_token => "OAuth Token" # # Basic auth expects # :basic_auth => {:user_name => "octocat", :password => "secret"} def initialize(hash={}) @hash = hash + @api_url = hash[:api_url] || 'https://api.github.com' + private_token = hash[:private_token] if hash.has_key?:private_token access_token = hash[:access_token] if hash.has_key?:access_token basic_auth = hash[:basic_auth] if hash.has_key?:basic_auth - super(hash[:api_url] || 'https://api.github.com') do |builder| + super(@api_url) do |builder| yield builder if block_given? builder.use Faraday::Response::RaiseGheeError builder.use FaradayMiddleware::EncodeJson @@ -33,6 +35,8 @@ def initialize(hash={}) builder.adapter Faraday.default_adapter end + # XXX Abstract into GitLab-specific class + self.headers["PRIVATE-TOKEN"] = private_token if private_token self.headers["Authorization"] = "token #{access_token}" if access_token self.basic_auth(basic_auth[:user_name], basic_auth[:password]) if basic_auth self.headers["Accept"] = 'application/vnd.github.v3.full+json' diff --git a/lib/ghee/github.rb b/lib/ghee/github.rb index eedbe9f..4efbe0d 100644 --- a/lib/ghee/github.rb +++ b/lib/ghee/github.rb @@ -1,4 +1,22 @@ class Ghee + def self.basic_auth(user_name, password, api_url = nil) + options = { :basic_auth => {:user_name => user_name, :password => password} } + options[:api_url] = api_url if api_url + Ghee.new options + end + + def self.access_token(token, api_url = nil) + options = { :access_token => token } + options[:api_url] = api_url if api_url + Ghee.new options + end + + def self.create_token(user_name, password, scopes, api_url = nil) + auth = Ghee.basic_auth(user_name, password, api_url).authorizations.create({ + :scopes => scopes}) + auth["token"] + end + module GitHub module API end diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb new file mode 100644 index 0000000..d8f3a61 --- /dev/null +++ b/lib/ghee/gitlab.rb @@ -0,0 +1,40 @@ +class Ghee + def self.private_token(token, api_url = nil) + options = { :private_token => token } + options[:enable_url_escape] = false + options[:api_url] = api_url if api_url + Ghee.new options + end + + module GitLab + module API + end + end +end + +#require 'ghee/gitlab/api/authorizations' +#require 'ghee/gitlab/api/gists' +#require 'ghee/gitlab/api/users' +#require 'ghee/gitlab/api/events' +require 'ghee/gitlab/api/repos' +#require 'ghee/gitlab/api/issues' +#require 'ghee/gitlab/api/milestones' +#require 'ghee/gitlab/api/orgs' +#require 'ghee/gitlab/api/git_data' +#require 'ghee/gitlab/api/labels' +#require 'ghee/gitlab/api/hooks' +#require 'ghee/gitlab/api/collaborators' +#require 'ghee/gitlab/api/forks' +#require 'ghee/gitlab/api/commits' +#require 'ghee/gitlab/api/commit_comments' +#require 'ghee/gitlab/api/commit_statuses' +#require 'ghee/gitlab/api/keys' +#require 'ghee/gitlab/api/watchers' +#require 'ghee/gitlab/api/emails' +#require 'ghee/gitlab/api/followers' +#require 'ghee/gitlab/api/pulls' +#require 'ghee/gitlab/api/search' +#require 'ghee/gitlab/api/contents' +#require 'ghee/gitlab/api/members' + +require 'ghee/gitlab/translators/repo_translator' diff --git a/lib/ghee/gitlab/api/repos.rb b/lib/ghee/gitlab/api/repos.rb new file mode 100644 index 0000000..6420747 --- /dev/null +++ b/lib/ghee/gitlab/api/repos.rb @@ -0,0 +1,35 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + attr_accessor :repo_name + end + + # Get repos + # + # name - String of the name of the repo + # + # Returns json + # + def repos(login, name = nil) + repo = name.nil? ? '' : "#{login}%2F#{name}" + path_prefix = "./projects/#{repo}" + proxy = Proxy.new(connection, path_prefix, ::Ghee::GitLab::RepoTranslator.new(:repo)) + proxy.repo_name = repo + proxy + end + end + end +end diff --git a/lib/ghee/gitlab/translators/repo_translator.rb b/lib/ghee/gitlab/translators/repo_translator.rb new file mode 100644 index 0000000..1c110a5 --- /dev/null +++ b/lib/ghee/gitlab/translators/repo_translator.rb @@ -0,0 +1,24 @@ +class Ghee + module GitLab + class RepoTranslator < Ghee::ApiTranslator + def translate_data(input) + if input.class == Array + input.map(&:translate_repo) + else + translate_repo(input) + end + end + + def translate_repo(input) + output = {} + output['full_name'] = input['path_with_namespace'] + output['private'] = !input['public'] + output['ssh_url'] = input['ssh_url_to_repo'] + output['html_url'] = input['web_url'] + output['has_issues'] = input['issues_enabled'] + # XXX Need open_issues_count in GitLab! + output + end + end + end +end diff --git a/lib/ghee/resource_proxy.rb b/lib/ghee/resource_proxy.rb index 334555c..3289fb2 100644 --- a/lib/ghee/resource_proxy.rb +++ b/lib/ghee/resource_proxy.rb @@ -13,7 +13,7 @@ class ResourceProxy include Ghee::CUD # Make connection and path_prefix readable - attr_reader :connection, :path_prefix, :params, :id + attr_reader :connection, :path_prefix, :api_translator, :params, :id # Expose pagination data attr_reader :current_page, :total, :pagination @@ -30,12 +30,14 @@ def self.accept_header(header) # connection - Ghee::Connection object # path_prefix - String # - def initialize(connection, path_prefix, params = {}, &block) + def initialize(connection, path_prefix, api_translator = nil, params = {}, &block) if !params.is_a?Hash @id = params - params = {} + params = {} end - @connection, @path_prefix, @params = connection, URI.escape(path_prefix), params + @connection, @path_prefix, @params = connection, path_prefix, params + @api_translator = api_translator + @path_prefix = URI.escape(@path_prefix) if connection.enable_url_escape @block = block if block subject if block end @@ -65,18 +67,26 @@ def raw # Returns json # def subject - @subject ||= connection.get(path_prefix) do |req| - req.params.merge!params - req.headers["Accept"] = accept_type if self.respond_to? :accept_type - @block.call(req)if @block - end.body + @subject ||= begin + response = connection.get(path_prefix) do |req| + req.params.merge!params + req.headers["Accept"] = accept_type if self.respond_to? :accept_type + @block.call(req)if @block + end + + if @api_translator + @api_translator.translate_data(response.body) + else + response.body + end + end end # Paginate is a helper method to handle # request pagination to the github api # # options - Hash containing pagination params - # eg; + # eg; # :per_page => 100, :page => 1 # # Returns self From df4c6969c7e93109603098e8b2cda0caa583f065 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 01:32:52 -0800 Subject: [PATCH 03/23] Remove trailing whitespace --- lib/ghee/resource_proxy.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ghee/resource_proxy.rb b/lib/ghee/resource_proxy.rb index 3289fb2..3d7f136 100644 --- a/lib/ghee/resource_proxy.rb +++ b/lib/ghee/resource_proxy.rb @@ -107,7 +107,7 @@ def paginate(options) parse_link_header response.headers.delete("link") - return self + return self end def all @@ -132,7 +132,7 @@ def all_parallel end end end - requests.inject([]) do |results, page| + requests.inject([]) do |results, page| results.concat(page.body) end end @@ -145,11 +145,11 @@ def all_parallel end def build_prefix(first_argument, endpoint) - (!first_argument.is_a?(Hash) && !first_argument.nil?) ? + (!first_argument.is_a?(Hash) && !first_argument.nil?) ? File.join(path_prefix, "/#{endpoint}/#{first_argument}") : File.join(path_prefix, "/#{endpoint}") end - private + private def pagination_data(header) parse_link_header header From 4f19c3d5bc2fbf52d692ed1f84d4db47517f241e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 01:38:29 -0800 Subject: [PATCH 04/23] Add empty API translator for GitHub calls --- lib/ghee/github/api/collaborators.rb | 2 +- lib/ghee/github/api/commit_comments.rb | 4 ++-- lib/ghee/github/api/commit_statuses.rb | 4 ++-- lib/ghee/github/api/commits.rb | 2 +- lib/ghee/github/api/contents.rb | 4 ++-- lib/ghee/github/api/events.rb | 4 ++-- lib/ghee/github/api/forks.rb | 2 +- lib/ghee/github/api/gists.rb | 2 +- lib/ghee/github/api/git_data.rb | 8 ++++---- lib/ghee/github/api/hooks.rb | 10 +++++----- lib/ghee/github/api/issues.rb | 8 ++++---- lib/ghee/github/api/labels.rb | 2 +- lib/ghee/github/api/members.rb | 4 ++-- lib/ghee/github/api/milestones.rb | 2 +- lib/ghee/github/api/orgs.rb | 18 +++++++++--------- lib/ghee/github/api/pulls.rb | 8 ++++---- lib/ghee/github/api/users.rb | 20 ++++++++++---------- 17 files changed, 52 insertions(+), 52 deletions(-) diff --git a/lib/ghee/github/api/collaborators.rb b/lib/ghee/github/api/collaborators.rb index f5eaaae..d58cb17 100644 --- a/lib/ghee/github/api/collaborators.rb +++ b/lib/ghee/github/api/collaborators.rb @@ -28,7 +28,7 @@ def remove(member) class Proxy < ::Ghee::ResourceProxy def collaborators(user=nil, &block) prefix = build_prefix user, "collaborators" - Collaborators::Proxy.new(connection, prefix, user, &block) + Collaborators::Proxy.new(connection, prefix, nil, user, &block) end end end diff --git a/lib/ghee/github/api/commit_comments.rb b/lib/ghee/github/api/commit_comments.rb index b0c787e..8024367 100644 --- a/lib/ghee/github/api/commit_comments.rb +++ b/lib/ghee/github/api/commit_comments.rb @@ -13,14 +13,14 @@ class Proxy < ::Ghee::ResourceProxy def comments(id=nil, &block) prefix = build_prefix id, "comments" - Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, id, &block + Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, nil, id, &block end end module Commits class Proxy < ::Ghee::ResourceProxy def comments(id=nil, &block) prefix = build_prefix id, "comments" - Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, id, &block + Ghee::API::Repos::Commits::Comments::Proxy.new connection, prefix, nil, id, &block end end module Comments diff --git a/lib/ghee/github/api/commit_statuses.rb b/lib/ghee/github/api/commit_statuses.rb index 4c7d4c5..b364331 100644 --- a/lib/ghee/github/api/commit_statuses.rb +++ b/lib/ghee/github/api/commit_statuses.rb @@ -17,11 +17,11 @@ class Proxy < ::Ghee::ResourceProxy def statuses(id=nil, &block) prefix = build_prefix id, "statuses" - Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, id, &block + Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, nil, id, &block end def status(&block) prefix = build_prefix nil, "status" - Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, id, &block + Ghee::API::Repos::Commits::Statuses::Proxy.new connection, prefix, nil, id, &block end end module Statuses diff --git a/lib/ghee/github/api/commits.rb b/lib/ghee/github/api/commits.rb index 34c4a60..99d270f 100644 --- a/lib/ghee/github/api/commits.rb +++ b/lib/ghee/github/api/commits.rb @@ -19,7 +19,7 @@ def compare(base, head) end def commits(sha=nil, &block) prefix = build_prefix sha, "commits" - Ghee::API::Repos::Commits::Proxy.new(connection, prefix, sha, &block) + Ghee::API::Repos::Commits::Proxy.new(connection, prefix, nil, sha, &block) end end diff --git a/lib/ghee/github/api/contents.rb b/lib/ghee/github/api/contents.rb index 5303b80..9b79769 100644 --- a/lib/ghee/github/api/contents.rb +++ b/lib/ghee/github/api/contents.rb @@ -34,12 +34,12 @@ def create(message, content=nil) class Proxy < ::Ghee::ResourceProxy def contents(path, &block) - proxy = Contents::Proxy.new connection, "#{path_prefix}/contents/#{path}", nil, &block + proxy = Contents::Proxy.new connection, "#{path_prefix}/contents/#{path}", nil, nil, &block proxy.path = path proxy end def readme(&block) - Contents::Proxy.new connection, "#{path_prefix}/readme", {}, &block + Contents::Proxy.new connection, "#{path_prefix}/readme", nil, {}, &block end end end diff --git a/lib/ghee/github/api/events.rb b/lib/ghee/github/api/events.rb index ff3b2b8..bac5c1c 100644 --- a/lib/ghee/github/api/events.rb +++ b/lib/ghee/github/api/events.rb @@ -17,9 +17,9 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def events(params={}) - return Proxy.new(connection, "./events",params) + return Proxy.new(connection, "./events", nil, params) end - + end end end diff --git a/lib/ghee/github/api/forks.rb b/lib/ghee/github/api/forks.rb index 83278ae..46a2bf7 100644 --- a/lib/ghee/github/api/forks.rb +++ b/lib/ghee/github/api/forks.rb @@ -24,7 +24,7 @@ def create(org=nil) # class Proxy < ::Ghee::ResourceProxy def forks(params={}) - Ghee::API::Repos::Forks::Proxy.new connection, "#{path_prefix}/forks", params + Ghee::API::Repos::Forks::Proxy.new connection, "#{path_prefix}/forks", nil, params end end end diff --git a/lib/ghee/github/api/gists.rb b/lib/ghee/github/api/gists.rb index 1967f7b..8e8980b 100644 --- a/lib/ghee/github/api/gists.rb +++ b/lib/ghee/github/api/gists.rb @@ -22,7 +22,7 @@ class Proxy < ::Ghee::ResourceProxy def comments(id = nil) prefix = id ? "#{path_prefix}/comments/#{id}" : "#{path_prefix}/comments" - return Ghee::API::Gists::Comments::Proxy.new connection, prefix + return Ghee::API::Gists::Comments::Proxy.new connection, nil, prefix end diff --git a/lib/ghee/github/api/git_data.rb b/lib/ghee/github/api/git_data.rb index 51fb137..f9205f1 100644 --- a/lib/ghee/github/api/git_data.rb +++ b/lib/ghee/github/api/git_data.rb @@ -64,15 +64,15 @@ class Proxy < ::Ghee::ResourceProxy def blobs(sha=nil, params={}) params = sha if sha.is_a?Hash prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/blobs/#{sha}" : "#{path_prefix}/blobs" - Ghee::API::Repos::Git::Blobs::Proxy.new(connection, prefix, params) + Ghee::API::Repos::Git::Blobs::Proxy.new(connection, prefix, nil, params) end - + # Get a commit by the sha # def commits(sha=nil, params={}) params = sha if sha.is_a?Hash prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/commits/#{sha}" : "#{path_prefix}/commits" - Ghee::API::Repos::Git::Commits::Proxy.new(connection, prefix, params) + Ghee::API::Repos::Git::Commits::Proxy.new(connection, prefix, nil, params) end # Get refs for the repo @@ -86,7 +86,7 @@ def refs(ref=nil) # def trees(sha=nil,params={}) prefix = sha ? "#{path_prefix}/trees/#{sha}" : "#{path_prefix}/trees" - Ghee::API::Repos::Git::Trees::Proxy.new(connection, prefix, params) + Ghee::API::Repos::Git::Trees::Proxy.new(connection, prefix, nil, params) end # Get a tag by a given sha diff --git a/lib/ghee/github/api/hooks.rb b/lib/ghee/github/api/hooks.rb index 90abcf5..e1eb360 100644 --- a/lib/ghee/github/api/hooks.rb +++ b/lib/ghee/github/api/hooks.rb @@ -14,10 +14,10 @@ module Repos module Hooks class Proxy < ::Ghee::ResourceProxy include Ghee::CUD - - # Test hook - This will trigger the hook with the - # latest push to the current repository. - # + + # Test hook - This will trigger the hook with the + # latest push to the current repository. + # def test connection.post("#{path_prefix}/test").body end @@ -37,7 +37,7 @@ class Proxy < ::Ghee::ResourceProxy def hooks(number=nil, params={}) params = number if number.is_a?Hash prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/hooks/#{number}" : "#{path_prefix}/hooks" - Ghee::API::Repos::Hooks::Proxy.new(connection, prefix, params) + Ghee::API::Repos::Hooks::Proxy.new(connection, prefix, nil, params) end end end diff --git a/lib/ghee/github/api/issues.rb b/lib/ghee/github/api/issues.rb index e46a76e..a8f8791 100644 --- a/lib/ghee/github/api/issues.rb +++ b/lib/ghee/github/api/issues.rb @@ -26,7 +26,7 @@ def assignees # module Issues - # API labels module handles all of the Github Issues + # API labels module handles all of the Github Issues # API endpoints # module Labels @@ -63,7 +63,7 @@ def remove end end - # API Comments module handles all of the Github Issues + # API Comments module handles all of the Github Issues # API endpoints # module Comments @@ -106,7 +106,7 @@ def closed response.body end - # Returns issue comments for an issue or all of the comments + # Returns issue comments for an issue or all of the comments # for a repo def comments(id=nil) prefix = id ? "#{path_prefix}/comments/#{id}" : "#{path_prefix}/comments" @@ -138,7 +138,7 @@ class Proxy < ::Ghee::ResourceProxy # def issues(number=nil) prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/issues/#{number}" : "#{path_prefix}/issues" - issue = Ghee::API::Repos::Issues::Proxy.new(connection, prefix, number) + issue = Ghee::API::Repos::Issues::Proxy.new(connection, prefix, nil, number) issue.repo = self issue end diff --git a/lib/ghee/github/api/labels.rb b/lib/ghee/github/api/labels.rb index b3efd19..7fc8b4f 100644 --- a/lib/ghee/github/api/labels.rb +++ b/lib/ghee/github/api/labels.rb @@ -29,7 +29,7 @@ class Proxy < ::Ghee::ResourceProxy def labels(number=nil, params={}) params = number if number.is_a?Hash prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/labels/#{number}" : "#{path_prefix}/labels" - Ghee::API::Repos::Labels::Proxy.new(connection, prefix, params) + Ghee::API::Repos::Labels::Proxy.new(connection, prefix, nil, params) end end end diff --git a/lib/ghee/github/api/members.rb b/lib/ghee/github/api/members.rb index 1cd96e7..439b650 100644 --- a/lib/ghee/github/api/members.rb +++ b/lib/ghee/github/api/members.rb @@ -4,11 +4,11 @@ module Orgs class Proxy < ::Ghee::ResourceProxy def members(id=nil, &block) prefix = build_prefix id, "members" - Ghee::API::Orgs::Members::Proxy.new connection, prefix, id, &block + Ghee::API::Orgs::Members::Proxy.new connection, prefix, nil, id, &block end def public_members(id=nil, &block) prefix = build_prefix id, "public_members" - Ghee::API::Orgs::PublicMembers::Proxy.new connection, prefix, id, &block + Ghee::API::Orgs::PublicMembers::Proxy.new connection, prefix, nil, id, &block end end module PublicMembers diff --git a/lib/ghee/github/api/milestones.rb b/lib/ghee/github/api/milestones.rb index 0aceb2e..9530a72 100644 --- a/lib/ghee/github/api/milestones.rb +++ b/lib/ghee/github/api/milestones.rb @@ -55,7 +55,7 @@ class Proxy < ::Ghee::ResourceProxy def milestones(number=nil, params={}) params = number if number.is_a?Hash prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/milestones/#{number}" : "#{path_prefix}/milestones" - Ghee::API::Repos::Milestones::Proxy.new(connection, prefix, params) + Ghee::API::Repos::Milestones::Proxy.new(connection, prefix, nil, params) end end end diff --git a/lib/ghee/github/api/orgs.rb b/lib/ghee/github/api/orgs.rb index 835a3fa..ab88c4b 100644 --- a/lib/ghee/github/api/orgs.rb +++ b/lib/ghee/github/api/orgs.rb @@ -25,7 +25,7 @@ module Teams # module Members - # Members::Proxy inherits from Ghee::Proxy and + # Members::Proxy inherits from Ghee::Proxy and # enables defining methods on the proxy object # class Proxy < ::Ghee::ResourceProxy @@ -44,7 +44,7 @@ def check?(username=nil) end end - # Teams::Proxy inherits from Ghee::Proxy and + # Teams::Proxy inherits from Ghee::Proxy and # enables defining methods on the proxy object # class Proxy < ::Ghee::ResourceProxy @@ -52,7 +52,7 @@ class Proxy < ::Ghee::ResourceProxy def members(name=nil, &block) prefix = name ? "#{path_prefix}/members/#{name}" : "#{path_prefix}/members" - Ghee::API::Orgs::Teams::Members::Proxy.new(connection, prefix, name, &block) + Ghee::API::Orgs::Teams::Members::Proxy.new(connection, prefix, nil, name, &block) end end @@ -70,7 +70,7 @@ class Proxy < ::Ghee::ResourceProxy # def teams(number=nil, &block) prefix = (!number.is_a?(Hash) and number) ? "./teams/#{number}" : "#{path_prefix}/teams" - Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, number, &block) + Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, nil, number, &block) end # Repos for a orgs @@ -80,7 +80,7 @@ def teams(number=nil, &block) def repos(name=nil, &block) params = name if name.is_a?Hash prefix = (!name.is_a?(Hash) and name) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos" - Ghee::API::Repos::Proxy.new(connection,prefix,name, &block) + Ghee::API::Repos::Proxy.new(connection,prefix, nil, name, &block) end # User Membership for an org @@ -90,7 +90,7 @@ def repos(name=nil, &block) def memberships(user, &block) prefix = "#{path_prefix}/memberships/#{user}" - Ghee::API::Orgs::Memberships::MembershipsProxy.new(connection, prefix, nil, &block) + Ghee::API::Orgs::Memberships::MembershipsProxy.new(connection, prefix, nil, nil, &block) end end @@ -99,11 +99,11 @@ def memberships(user, &block) # Returns json # def team(number, params={}) - prefix = "./teams/#{number}" - Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, params) + prefix = "./teams/#{number}" + Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, nil, params) end - # Returns list of the authenticated users organizations or + # Returns list of the authenticated users organizations or # an organization by name # # org - String name of the organization (optional) diff --git a/lib/ghee/github/api/pulls.rb b/lib/ghee/github/api/pulls.rb index 0cc12c0..feffae7 100644 --- a/lib/ghee/github/api/pulls.rb +++ b/lib/ghee/github/api/pulls.rb @@ -17,15 +17,15 @@ class Proxy < ::Ghee::ResourceProxy def commits connection.get("#{path_prefix}/commits").body end - + def files connection.get("#{path_prefix}/files").body end - + def merge? connection.get("#{path_prefix}/merge").status == 204 end - + def merge!(message=nil) params = message ? {:commit_message=>message} : {} connection.put("#{path_prefix}/merge", params).body @@ -40,7 +40,7 @@ class Proxy < ::Ghee::ResourceProxy def pulls(number=nil, params={}) params = number if number.is_a?Hash prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/pulls/#{number}" : "#{path_prefix}/pulls" - Ghee::API::Repos::Pulls::Proxy.new(connection, prefix, params) + Ghee::API::Repos::Pulls::Proxy.new(connection, prefix, nil, params) end end end diff --git a/lib/ghee/github/api/users.rb b/lib/ghee/github/api/users.rb index 961c22e..9adce98 100644 --- a/lib/ghee/github/api/users.rb +++ b/lib/ghee/github/api/users.rb @@ -29,13 +29,13 @@ module Users # module Memberships - # Memberships::Proxy inherits from Ghee::Proxy and + # Memberships::Proxy inherits from Ghee::Proxy and # enables defining methods on the proxy object # class Proxy < ::Ghee::ResourceProxy #Org membership for the user # - #State: string to limit scope to either active or + #State: string to limit scope to either active or #pending # #Returns json @@ -58,7 +58,7 @@ class Proxy < ::Ghee::ResourceProxy # Returns json # def gists(params={}) - Ghee::API::Gists::Proxy.new(connection,"#{path_prefix}/gists", params) + Ghee::API::Gists::Proxy.new(connection,"#{path_prefix}/gists", nil, params) end # Repos for a user @@ -67,11 +67,11 @@ def gists(params={}) # def repos(name=nil, params={}) params = name if name.is_a?Hash - prefix = name.is_a?(String) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos" - Ghee::API::Repos::Proxy.new(connection,prefix, params) + prefix = name.is_a?(String) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos" + Ghee::API::Repos::Proxy.new(connection, prefix, nil, params) end - # Returns list of the provided users organizations or + # Returns list of the provided users organizations or # an organization by name # # org - String name of the organization (optional) @@ -81,13 +81,13 @@ def repos(name=nil, params={}) def orgs(org=nil, params={}) params = org if org.is_a?Hash prefix = org.is_a?(String) ? "./orgs/#{org}" : "#{path_prefix}/orgs" - Ghee::API::Orgs::Proxy.new(connection, prefix, params) + Ghee::API::Orgs::Proxy.new(connection, prefix, nil, params) end - # Returns a Memberships Proxy + # Returns a Memberships Proxy def memberships(params={state: "active"}, &block) prefix = "#{path_prefix}/memberships/orgs" - Ghee::API::Users::Memberships::Proxy.new(connection, prefix, params, &block) + Ghee::API::Users::Memberships::Proxy.new(connection, prefix, nil, params, &block) end end @@ -96,7 +96,7 @@ def memberships(params={state: "active"}, &block) # Returns json # def user(&block) - Proxy.new(connection, './user', nil, &block) + Proxy.new(connection, './user', nil, nil, &block) end # Get a single user From 9041329fae10e110877e669cc0d8f7eda858f35b Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 01:42:12 -0800 Subject: [PATCH 05/23] Move translators into api directory --- lib/ghee/gitlab.rb | 2 +- lib/ghee/gitlab/{ => api}/translators/repo_translator.rb | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/ghee/gitlab/{ => api}/translators/repo_translator.rb (100%) diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index d8f3a61..dbfb721 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -37,4 +37,4 @@ module API #require 'ghee/gitlab/api/contents' #require 'ghee/gitlab/api/members' -require 'ghee/gitlab/translators/repo_translator' +require 'ghee/gitlab/api/translators/repo_translator' diff --git a/lib/ghee/gitlab/translators/repo_translator.rb b/lib/ghee/gitlab/api/translators/repo_translator.rb similarity index 100% rename from lib/ghee/gitlab/translators/repo_translator.rb rename to lib/ghee/gitlab/api/translators/repo_translator.rb From 56885df3770e52440afad8b3e8b1ff090237bd0c Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 02:00:30 -0800 Subject: [PATCH 06/23] Add user API translation --- lib/ghee/api_translator.rb | 8 ++ lib/ghee/gitlab.rb | 3 +- .../gitlab/api/translators/repo_translator.rb | 10 +- .../gitlab/api/translators/user_translator.rb | 14 +++ lib/ghee/gitlab/api/users.rb | 110 ++++++++++++++++++ 5 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 lib/ghee/gitlab/api/translators/user_translator.rb create mode 100644 lib/ghee/gitlab/api/users.rb diff --git a/lib/ghee/api_translator.rb b/lib/ghee/api_translator.rb index 3c81a88..ed5bdff 100644 --- a/lib/ghee/api_translator.rb +++ b/lib/ghee/api_translator.rb @@ -7,6 +7,14 @@ def initialize(context) end def translate_data(data) + if data.class == Array + data.map{ |input| translate_hash(input) } + else + translate_hash(data) + end + end + + def translate_hash(input) raise NotImplemented end end diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index dbfb721..e4635ca 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -14,7 +14,7 @@ module API #require 'ghee/gitlab/api/authorizations' #require 'ghee/gitlab/api/gists' -#require 'ghee/gitlab/api/users' +require 'ghee/gitlab/api/users' #require 'ghee/gitlab/api/events' require 'ghee/gitlab/api/repos' #require 'ghee/gitlab/api/issues' @@ -38,3 +38,4 @@ module API #require 'ghee/gitlab/api/members' require 'ghee/gitlab/api/translators/repo_translator' +require 'ghee/gitlab/api/translators/user_translator' diff --git a/lib/ghee/gitlab/api/translators/repo_translator.rb b/lib/ghee/gitlab/api/translators/repo_translator.rb index 1c110a5..21125c5 100644 --- a/lib/ghee/gitlab/api/translators/repo_translator.rb +++ b/lib/ghee/gitlab/api/translators/repo_translator.rb @@ -1,15 +1,7 @@ class Ghee module GitLab class RepoTranslator < Ghee::ApiTranslator - def translate_data(input) - if input.class == Array - input.map(&:translate_repo) - else - translate_repo(input) - end - end - - def translate_repo(input) + def translate_hash(input) output = {} output['full_name'] = input['path_with_namespace'] output['private'] = !input['public'] diff --git a/lib/ghee/gitlab/api/translators/user_translator.rb b/lib/ghee/gitlab/api/translators/user_translator.rb new file mode 100644 index 0000000..e8a73a2 --- /dev/null +++ b/lib/ghee/gitlab/api/translators/user_translator.rb @@ -0,0 +1,14 @@ +class Ghee + module GitLab + class UserTranslator < Ghee::ApiTranslator + def translate_hash(data) + new_user = {} + new_user['id'] = data['id'] + new_user['login'] = data['username'] + new_user['name'] = data['name'] + new_user['email'] = data['email'] if data['email'] + new_user + end + end + end +end diff --git a/lib/ghee/gitlab/api/users.rb b/lib/ghee/gitlab/api/users.rb new file mode 100644 index 0000000..0cb3c33 --- /dev/null +++ b/lib/ghee/gitlab/api/users.rb @@ -0,0 +1,110 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + module Membership + class MembershipProxy < ::Ghee::ResourceProxy + def admin? + raise NotImplemented + end + def active? + raise NotImplemented + end + def activate! + raise NotImplemented + end + end + end + + # The Users module handles all of the Github User + # API endpoints + # + module Users + + #Users::Memberships modules handles a users memberships + # + # + module Memberships + + # Memberships::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + #Org membership for the user + # + #State: string to limit scope to either active or + #pending + # + #Returns json + def org(name, &block) + raise NotImplemented + end + end + end + + # Users::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + # Gists for a user + # + # Returns json + # + def gists(params={}) + # GitLab doesn't support retrieval of snippets per user + raise NotImplemented + end + + # Repos for a user + # + # Returns json + # + def repos(name=nil, params={}) +# params = name if name.is_a?Hash +# prefix = name.is_a?(String) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/projects" + prefix = "#{connection.api_url}/projects" + Ghee::API::Repos::Proxy.new(connection, prefix, ::Ghee::GitLab::RepoTranslator.new(nil), params) + end + + # Returns list of the provided users organizations or + # an organization by name + # + # org - String name of the organization (optional) + # + # Returns json + # + def orgs(org=nil, params={}) + raise NotImplemented + end + + # Returns a Memberships Proxy + def memberships(params={state: "active"}, &block) + raise NotImplemented + end + end + + # Get authenticated user + # + # Returns json + # + def user(&block) + Proxy.new(connection, './user', ::Ghee::GitLab::UserTranslator.new(:user), nil, &block) + end + + # Get a single user + # + # user - String of user login + # + # Returns json + # + def users(user) + # GitLab doesn't support retrieval by username yet (only by ID) + raise NotImplemented + end + end + end +end From c3cabb12d6b26cdb214aa116585f3606ca5c3a21 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 02:14:58 -0800 Subject: [PATCH 07/23] Add issue and milestone translation --- lib/ghee/gitlab.rb | 4 +- lib/ghee/gitlab/api/issues.rb | 151 ++++++++++++++++++ .../api/translators/issue_translator.rb | 35 ++++ .../api/translators/milestone_translator.rb | 15 ++ 4 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 lib/ghee/gitlab/api/issues.rb create mode 100644 lib/ghee/gitlab/api/translators/issue_translator.rb create mode 100644 lib/ghee/gitlab/api/translators/milestone_translator.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index e4635ca..35136c6 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -17,7 +17,7 @@ module API require 'ghee/gitlab/api/users' #require 'ghee/gitlab/api/events' require 'ghee/gitlab/api/repos' -#require 'ghee/gitlab/api/issues' +require 'ghee/gitlab/api/issues' #require 'ghee/gitlab/api/milestones' #require 'ghee/gitlab/api/orgs' #require 'ghee/gitlab/api/git_data' @@ -39,3 +39,5 @@ module API require 'ghee/gitlab/api/translators/repo_translator' require 'ghee/gitlab/api/translators/user_translator' +require 'ghee/gitlab/api/translators/issue_translator' +require 'ghee/gitlab/api/translators/milestone_translator' diff --git a/lib/ghee/gitlab/api/issues.rb b/lib/ghee/gitlab/api/issues.rb new file mode 100644 index 0000000..3862803 --- /dev/null +++ b/lib/ghee/gitlab/api/issues.rb @@ -0,0 +1,151 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + module Repos + + module Assignees + class Proxy < ::Ghee::ResourceProxy + def check?(member) + connection.get("#{path_prefix}/#{member}").status == 204 + end + end + end + class Proxy < ::Ghee::ResourceProxy + def assignees + prefix = "#{path_prefix}/assignees" + Ghee::API::GitLab::Repos::Assignees::Proxy.new(connection, prefix) + end + end + + # The Issues module handles all of the GitLab Repo Issues + # API endpoints + # + module Issues + + # API labels module handles all of the GitLab Issues + # API endpoints + # + module Labels + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + undef_method "create" + + # Creates label for an issue using the authenicated user + # + # labels - Array of labels + # + # return json + # + def add(labels) + connection.post(path_prefix,labels).body + end + + # Patchs and existing label + # + # return json + # + def replace(labels) + connection.put(path_prefix, labels).body + end + + # Destroys label by id + # + # return boolean + # + def remove + connection.delete(path_prefix).status == 204 + end + end + end + + # API Comments module handles all of the GitLab Issues + # API endpoints + # + module Comments + class Proxy < ::Ghee::ResourceProxy + end + end + + module Events + class Proxy < ::Ghee::ResourceProxy + undef_method "patch" + undef_method "destroy" + undef_method "create" + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + attr_accessor :repo + + # Close issue - closed issue by id + # + # usage - ghee.repos("my_repo").issues(1).close + # + # returns boolean + # + def close + connection.put(path_prefix, :state_event => "closed").status = 200 + end + + # Returns closed issues + # + # Returns json + # + def closed + response = connection.get path_prefix do |req| + req.params["state"] = "closed" + end + response.body + end + + # Returns issue comments for an issue or all of the comments + # for a repo + def comments(id=nil) + return [] if id.nil? + prefix = id ? "#{path_prefix}/notes/#{id}" : "#{path_prefix}/notes" + Ghee::API::GitLab::Repos::Issues::Comments::Proxy.new(connection,prefix) + end + + # Returns all of the labels for repo + # + def labels + # Not supported yet: GitLab needs to retrieve by repo_path instead of issues/repo_path + raise NotImplemented + end + + # Returns issue events for a repo or issue number + # + def events(id=nil) + # Not supported yet: GitLab system notes do not have metadata + raise NotImplemented + end + + end + end + + class Proxy < ::Ghee::ResourceProxy + attr_accessor :issue_path + + RemapDef = Struct.new(:in_key, :out_key) + + # Get issues + # + # Returns json + # + def issues(number=nil) + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/issues/#{number}" : "#{path_prefix}/issues" + issue = Ghee::API::Repos::Issues::Proxy.new(connection, prefix, ::Ghee::GitLab::IssueTranslator.new(:issue)) + issue.repo = self + issue + end + end + end + end +end diff --git a/lib/ghee/gitlab/api/translators/issue_translator.rb b/lib/ghee/gitlab/api/translators/issue_translator.rb new file mode 100644 index 0000000..e6d32cb --- /dev/null +++ b/lib/ghee/gitlab/api/translators/issue_translator.rb @@ -0,0 +1,35 @@ +class Ghee + module GitLab + class IssueTranslator < Ghee::ApiTranslator + def translate_hash(input) + output = {} + store_passthrough(input, output) + store_remapped(input, output) + output + end + + def store_passthrough(input, output) + attributes = %w(id title state assignee state updated_at created_at milestone) + attributes.each do |attr| + output[attr] = input[attr] + end + end + + def store_remapped(input, output) + output['id'] = input['iid'] + output['user'] = {} + output['user']['id'] = input['author']['id'] + output['user']['login'] = input['author']['username'] + + output['milestone'] = nil + + if input['milestone'] + translator = MilestoneTranslator.new(:milestone) + output['milestone'] = translator.translate_hash(input['milestone']) + end + + output + end + end + end +end diff --git a/lib/ghee/gitlab/api/translators/milestone_translator.rb b/lib/ghee/gitlab/api/translators/milestone_translator.rb new file mode 100644 index 0000000..80691ad --- /dev/null +++ b/lib/ghee/gitlab/api/translators/milestone_translator.rb @@ -0,0 +1,15 @@ +class Ghee + module GitLab + class MilestoneTranslator < Ghee::ApiTranslator + def translate_hash(input) + output = {} + output['id'] = input['id'] + output['title'] = input['title'] + output['due_on'] = input['due_date'] + output['created_at'] = input['created_at'] + output['updated_at'] = input['updated_at'] + output + end + end + end +end From a8adde7de68f669f5c0afa0f4c4da0833032bf5e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 11 Dec 2015 08:55:16 -0800 Subject: [PATCH 08/23] Add support for commits --- lib/ghee/gitlab.rb | 3 +- lib/ghee/gitlab/api/commits.rb | 35 +++++++++++++++++++ .../api/translators/commit_translator.rb | 16 +++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lib/ghee/gitlab/api/commits.rb create mode 100644 lib/ghee/gitlab/api/translators/commit_translator.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index 35136c6..edeb224 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -25,7 +25,7 @@ module API #require 'ghee/gitlab/api/hooks' #require 'ghee/gitlab/api/collaborators' #require 'ghee/gitlab/api/forks' -#require 'ghee/gitlab/api/commits' +require 'ghee/gitlab/api/commits' #require 'ghee/gitlab/api/commit_comments' #require 'ghee/gitlab/api/commit_statuses' #require 'ghee/gitlab/api/keys' @@ -37,6 +37,7 @@ module API #require 'ghee/gitlab/api/contents' #require 'ghee/gitlab/api/members' +require 'ghee/gitlab/api/translators/commit_translator' require 'ghee/gitlab/api/translators/repo_translator' require 'ghee/gitlab/api/translators/user_translator' require 'ghee/gitlab/api/translators/issue_translator' diff --git a/lib/ghee/gitlab/api/commits.rb b/lib/ghee/gitlab/api/commits.rb new file mode 100644 index 0000000..9fcf947 --- /dev/null +++ b/lib/ghee/gitlab/api/commits.rb @@ -0,0 +1,35 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + # Repos::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + def compare(base, head) + # GitLab does not support comparison of two SHA IDs via API + raise NotImplemented + end + def commits(sha=nil, &block) + prefix = build_prefix sha, "/repository/commits" + Ghee::API::Repos::Commits::Proxy.new(connection, prefix, ::Ghee::GitLab::CommitTranslator.new(:commits), sha, &block) + end + end + + module Commits + class Proxy < ::Ghee::ResourceProxy + end + end + end + end +end + + diff --git a/lib/ghee/gitlab/api/translators/commit_translator.rb b/lib/ghee/gitlab/api/translators/commit_translator.rb new file mode 100644 index 0000000..de773f5 --- /dev/null +++ b/lib/ghee/gitlab/api/translators/commit_translator.rb @@ -0,0 +1,16 @@ +class Ghee + module GitLab + class CommitTranslator < Ghee::ApiTranslator + def translate_hash(input) + output = {} + output['sha'] = input['id'] + output['tree'] = { sha: input['id'] } + output['commit'] = {} + output['commit'] = { message: input['title'] } + output['commit']['author'] = { email: input['author_email'], + name: input['author_name'] } + output + end + end + end +end From 0162ae140e0f56d3238479fd8bf8a8265ab8f39a Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 18:10:23 -0800 Subject: [PATCH 09/23] Remove unnecessary definition --- lib/ghee/gitlab/api/issues.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ghee/gitlab/api/issues.rb b/lib/ghee/gitlab/api/issues.rb index 3862803..cf213ac 100644 --- a/lib/ghee/gitlab/api/issues.rb +++ b/lib/ghee/gitlab/api/issues.rb @@ -133,8 +133,6 @@ def events(id=nil) class Proxy < ::Ghee::ResourceProxy attr_accessor :issue_path - RemapDef = Struct.new(:in_key, :out_key) - # Get issues # # Returns json From 0bba3c8c687c71dd3d3a0862ea9b2fc764a8d379 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 18:10:52 -0800 Subject: [PATCH 10/23] Add labels in issues translation --- lib/ghee/gitlab.rb | 1 + lib/ghee/gitlab/api/issues.rb | 5 ++--- .../gitlab/api/translators/issue_translator.rb | 13 ++++++++++--- .../gitlab/api/translators/labels_translator.rb | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 lib/ghee/gitlab/api/translators/labels_translator.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index edeb224..e897f16 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -41,4 +41,5 @@ module API require 'ghee/gitlab/api/translators/repo_translator' require 'ghee/gitlab/api/translators/user_translator' require 'ghee/gitlab/api/translators/issue_translator' +require 'ghee/gitlab/api/translators/labels_translator' require 'ghee/gitlab/api/translators/milestone_translator' diff --git a/lib/ghee/gitlab/api/issues.rb b/lib/ghee/gitlab/api/issues.rb index cf213ac..11410ed 100644 --- a/lib/ghee/gitlab/api/issues.rb +++ b/lib/ghee/gitlab/api/issues.rb @@ -116,14 +116,13 @@ def comments(id=nil) # Returns all of the labels for repo # def labels - # Not supported yet: GitLab needs to retrieve by repo_path instead of issues/repo_path - raise NotImplemented + Ghee::API::Repos::Issues::Proxy.new(connection, path_prefix, ::Ghee::GitLab::IssueTranslator.new(:extract_labels)) end # Returns issue events for a repo or issue number # def events(id=nil) - # Not supported yet: GitLab system notes do not have metadata + # Not supported yet: GitLab can't filter events by issue raise NotImplemented end diff --git a/lib/ghee/gitlab/api/translators/issue_translator.rb b/lib/ghee/gitlab/api/translators/issue_translator.rb index e6d32cb..d13dc13 100644 --- a/lib/ghee/gitlab/api/translators/issue_translator.rb +++ b/lib/ghee/gitlab/api/translators/issue_translator.rb @@ -2,9 +2,16 @@ class Ghee module GitLab class IssueTranslator < Ghee::ApiTranslator def translate_hash(input) - output = {} - store_passthrough(input, output) - store_remapped(input, output) + case context + when :extract_labels + label_translator = LabelsTranslator.new(:labels) + output = label_translator.translate_hash(input['labels']) + else + output = {} + store_passthrough(input, output) + store_remapped(input, output) + end + output end diff --git a/lib/ghee/gitlab/api/translators/labels_translator.rb b/lib/ghee/gitlab/api/translators/labels_translator.rb new file mode 100644 index 0000000..b0031e2 --- /dev/null +++ b/lib/ghee/gitlab/api/translators/labels_translator.rb @@ -0,0 +1,14 @@ +class Ghee + module GitLab + class LabelsTranslator < Ghee::ApiTranslator + def translate_hash(input) + output = [] + input.each do |label| + output.push({'name' => label }) + end + + output + end + end + end +end From 8392f52ac48234532052762cc36eca073119aab6 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 18:11:07 -0800 Subject: [PATCH 11/23] Add open_issues_count to repo in preparation of GitLab support --- lib/ghee/gitlab/api/translators/repo_translator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ghee/gitlab/api/translators/repo_translator.rb b/lib/ghee/gitlab/api/translators/repo_translator.rb index 21125c5..a508f5d 100644 --- a/lib/ghee/gitlab/api/translators/repo_translator.rb +++ b/lib/ghee/gitlab/api/translators/repo_translator.rb @@ -8,7 +8,8 @@ def translate_hash(input) output['ssh_url'] = input['ssh_url_to_repo'] output['html_url'] = input['web_url'] output['has_issues'] = input['issues_enabled'] - # XXX Need open_issues_count in GitLab! + # This is only available in GitLab 8.3 + output['open_issues_count'] = input.fetch('issues_enabled', 0) output end end From 5b73977586b34aca8443e2b3faf3a7ecb1c840b0 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 18:14:18 -0800 Subject: [PATCH 12/23] Add labels to GitLab issues --- lib/ghee/gitlab/api/translators/issue_translator.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ghee/gitlab/api/translators/issue_translator.rb b/lib/ghee/gitlab/api/translators/issue_translator.rb index d13dc13..fee814f 100644 --- a/lib/ghee/gitlab/api/translators/issue_translator.rb +++ b/lib/ghee/gitlab/api/translators/issue_translator.rb @@ -35,6 +35,8 @@ def store_remapped(input, output) output['milestone'] = translator.translate_hash(input['milestone']) end + label_translator = LabelsTranslator.new(:labels) + output['labels'] = label_translator.translate_hash(input['labels']) output end end From 9cd51622d2f76f9b68d92b1a9686eb783d149869 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 19:38:48 -0800 Subject: [PATCH 13/23] Add support for GitLab milestones --- lib/ghee/gitlab.rb | 2 +- lib/ghee/gitlab/api/milestones.rb | 63 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 lib/ghee/gitlab/api/milestones.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index e897f16..af77a85 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -18,7 +18,7 @@ module API #require 'ghee/gitlab/api/events' require 'ghee/gitlab/api/repos' require 'ghee/gitlab/api/issues' -#require 'ghee/gitlab/api/milestones' +require 'ghee/gitlab/api/milestones' #require 'ghee/gitlab/api/orgs' #require 'ghee/gitlab/api/git_data' #require 'ghee/gitlab/api/labels' diff --git a/lib/ghee/gitlab/api/milestones.rb b/lib/ghee/gitlab/api/milestones.rb new file mode 100644 index 0000000..c124fba --- /dev/null +++ b/lib/ghee/gitlab/api/milestones.rb @@ -0,0 +1,63 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + module Repos + + # The Milestones module handles all of the Github Repo Milestones + # API endpoints + # + module Milestones + + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + # Close milestone - closed milestone by id + # + # usage - ghee.repos("my_repo").milestones(1).close + # + # returns boolean + # + def close + connection.put(path_prefix,:state_event => "closed").status == 200 + end + + # Returns closed milestones + # + # Returns json + # + def closed + response = connection.get path_prefix do |req| + req.params["state"] = "closed" + end + response.body + end + + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + # Get milestones + # + # Returns json + # + def milestones(number=nil, params={}) + params = number if number.is_a?Hash + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/milestones/#{number}" : "#{path_prefix}/milestones" + Ghee::API::Repos::Milestones::Proxy.new(connection, prefix, ::Ghee::GitLab::MilestoneTranslator.new(:milestone), params) + end + end + end + end +end From d1f52c32809949ee94e55a15184c012503b67500 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 20:09:09 -0800 Subject: [PATCH 14/23] Add support for assignees (team members in GitLab) --- lib/ghee/gitlab.rb | 1 + lib/ghee/gitlab/api/issues.rb | 11 +++++----- lib/ghee/gitlab/api/repos.rb | 14 +++++++++++++ .../api/translators/assignee_translator.rb | 21 +++++++++++++++++++ .../gitlab/api/translators/user_translator.rb | 1 + 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 lib/ghee/gitlab/api/translators/assignee_translator.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index af77a85..cd639f2 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -37,6 +37,7 @@ module API #require 'ghee/gitlab/api/contents' #require 'ghee/gitlab/api/members' +require 'ghee/gitlab/api/translators/assignee_translator' require 'ghee/gitlab/api/translators/commit_translator' require 'ghee/gitlab/api/translators/repo_translator' require 'ghee/gitlab/api/translators/user_translator' diff --git a/lib/ghee/gitlab/api/issues.rb b/lib/ghee/gitlab/api/issues.rb index 11410ed..696b37b 100644 --- a/lib/ghee/gitlab/api/issues.rb +++ b/lib/ghee/gitlab/api/issues.rb @@ -12,11 +12,12 @@ def check?(member) connection.get("#{path_prefix}/#{member}").status == 204 end end - end - class Proxy < ::Ghee::ResourceProxy - def assignees - prefix = "#{path_prefix}/assignees" - Ghee::API::GitLab::Repos::Assignees::Proxy.new(connection, prefix) + + class Proxy < ::Ghee::ResourceProxy + def assignees + prefix = "#{path_prefix}/assignees" + Ghee::API::GitLab::Repos::Assignees::Proxy.new(connection, prefix, ::Ghee::GitLab::AssigneeTranslator.new(:assignees)) + end end end diff --git a/lib/ghee/gitlab/api/repos.rb b/lib/ghee/gitlab/api/repos.rb index 6420747..5897adb 100644 --- a/lib/ghee/gitlab/api/repos.rb +++ b/lib/ghee/gitlab/api/repos.rb @@ -10,6 +10,20 @@ module API # module Repos + module Assignees + class Proxy < ::Ghee::ResourceProxy + def check?(member) + raise NotImplemented + end + end + end + class Proxy < ::Ghee::ResourceProxy + def assignees + prefix = "#{path_prefix}/members" + Ghee::API::Repos::Assignees::Proxy.new(connection, prefix, ::Ghee::GitLab::AssigneeTranslator.new(:assignees)) + end + end + # Gists::Proxy inherits from Ghee::Proxy and # enables defining methods on the proxy object # diff --git a/lib/ghee/gitlab/api/translators/assignee_translator.rb b/lib/ghee/gitlab/api/translators/assignee_translator.rb new file mode 100644 index 0000000..bd8c5c5 --- /dev/null +++ b/lib/ghee/gitlab/api/translators/assignee_translator.rb @@ -0,0 +1,21 @@ +class Ghee + module GitLab + class AssigneeTranslator < Ghee::ApiTranslator + GUEST = 10 + REPORTER = 20 + DEVELOPER = 30 + MASTER = 40 + OWNER = 50 + + def translate_hash(data) + new_user = {} + new_user['id'] = data['id'] + new_user['login'] = data['username'] + new_user['avatar_url'] = data['avatar_url'] + new_user['type'] = 'user' + new_user['site_admin'] = data['access_level'].to_i > DEVELOPER + new_user + end + end + end +end diff --git a/lib/ghee/gitlab/api/translators/user_translator.rb b/lib/ghee/gitlab/api/translators/user_translator.rb index e8a73a2..a91f195 100644 --- a/lib/ghee/gitlab/api/translators/user_translator.rb +++ b/lib/ghee/gitlab/api/translators/user_translator.rb @@ -5,6 +5,7 @@ def translate_hash(data) new_user = {} new_user['id'] = data['id'] new_user['login'] = data['username'] + new_user['avatar_url'] = data['avatar_url'] new_user['name'] = data['name'] new_user['email'] = data['email'] if data['email'] new_user From a62536ba8483391b5eb5a9fc1fba40bbcef54262 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 20:12:35 -0800 Subject: [PATCH 15/23] Map GitLab milestone iid -> milestone number --- lib/ghee/gitlab/api/translators/milestone_translator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ghee/gitlab/api/translators/milestone_translator.rb b/lib/ghee/gitlab/api/translators/milestone_translator.rb index 80691ad..c1771d8 100644 --- a/lib/ghee/gitlab/api/translators/milestone_translator.rb +++ b/lib/ghee/gitlab/api/translators/milestone_translator.rb @@ -4,6 +4,7 @@ class MilestoneTranslator < Ghee::ApiTranslator def translate_hash(input) output = {} output['id'] = input['id'] + output['number'] = input['iid'] output['title'] = input['title'] output['due_on'] = input['due_date'] output['created_at'] = input['created_at'] From 31477730517acabbb70346e6054098c42433c629 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 20:20:41 -0800 Subject: [PATCH 16/23] Map GitLab iid -> GitHub number --- lib/ghee/gitlab/api/translators/issue_translator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ghee/gitlab/api/translators/issue_translator.rb b/lib/ghee/gitlab/api/translators/issue_translator.rb index fee814f..8eaa0e2 100644 --- a/lib/ghee/gitlab/api/translators/issue_translator.rb +++ b/lib/ghee/gitlab/api/translators/issue_translator.rb @@ -23,7 +23,8 @@ def store_passthrough(input, output) end def store_remapped(input, output) - output['id'] = input['iid'] + output['id'] = input['id'] + output['number'] = input['iid'] output['user'] = {} output['user']['id'] = input['author']['id'] output['user']['login'] = input['author']['username'] From 3fdf0beddd9b252e58d2a8e2e5ce115ce4c2663c Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 22:32:21 -0800 Subject: [PATCH 17/23] Add GitLab API lookup by username --- lib/ghee/gitlab/api/users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ghee/gitlab/api/users.rb b/lib/ghee/gitlab/api/users.rb index 0cb3c33..7f629fd 100644 --- a/lib/ghee/gitlab/api/users.rb +++ b/lib/ghee/gitlab/api/users.rb @@ -103,7 +103,7 @@ def user(&block) # def users(user) # GitLab doesn't support retrieval by username yet (only by ID) - raise NotImplemented + Proxy.new(connection, "./users?username=#{user}", ::Ghee::GitLab::UserTranslator.new(:user)) end end end From d9a9e1e273750571bd4f7ad020800050437aeb64 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 12 Dec 2015 22:33:34 -0800 Subject: [PATCH 18/23] Support mapping from organizations -> groups --- lib/ghee/gitlab.rb | 3 +- lib/ghee/gitlab/api/orgs.rb | 114 ++++++++++++++++++ .../gitlab/api/translators/org_translator.rb | 14 +++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 lib/ghee/gitlab/api/orgs.rb create mode 100644 lib/ghee/gitlab/api/translators/org_translator.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index cd639f2..37a8a29 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -19,7 +19,7 @@ module API require 'ghee/gitlab/api/repos' require 'ghee/gitlab/api/issues' require 'ghee/gitlab/api/milestones' -#require 'ghee/gitlab/api/orgs' +require 'ghee/gitlab/api/orgs' #require 'ghee/gitlab/api/git_data' #require 'ghee/gitlab/api/labels' #require 'ghee/gitlab/api/hooks' @@ -39,6 +39,7 @@ module API require 'ghee/gitlab/api/translators/assignee_translator' require 'ghee/gitlab/api/translators/commit_translator' +require 'ghee/gitlab/api/translators/org_translator' require 'ghee/gitlab/api/translators/repo_translator' require 'ghee/gitlab/api/translators/user_translator' require 'ghee/gitlab/api/translators/issue_translator' diff --git a/lib/ghee/gitlab/api/orgs.rb b/lib/ghee/gitlab/api/orgs.rb new file mode 100644 index 0000000..deaa954 --- /dev/null +++ b/lib/ghee/gitlab/api/orgs.rb @@ -0,0 +1,114 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Orgs module handles all of the Github Organization + # API endpoints + # + module Orgs + + module Memberships + class MembershipsProxy < ::Ghee::ResourceProxy + end + end + + # Orgs::Teams module handles all of the Github Organization Teams + # API endpoints + # + module Teams + + # Orgs::Teams::Members module handles all of the Github Organization Teams members + # API endpoints + # + module Members + + # Members::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + def add(member) + raise NotImplemented + end + + def remove(member) + raise NotImplemented + end + + def check?(username=nil) + raise NotImplemented + end + end + end + + # Teams::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + def members(name=nil, &block) + raise NotImplemented + end + end + end + + # Orgs::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + include Ghee::CUD + + # Teams for an org + # + # Returns json + # + def teams(number=nil, &block) + raise NotImplemented + end + + # Repos for a orgs + # + # Returns json + # + def repos(name=nil, &block) + raise NotImplemented + end + + # User Membership for an org + # + # Returns json + # + + def memberships(user, &block) + raise NotImplemented + end + end + + # Team by id + # + # Returns json + # + def team(number, params={}) + # GitLab + raise NotImplemented + end + + # Returns list of the authenticated users organizations or + # an organization by name + # + # org - String name of the organization (optional) + # + # Returns json + # + def orgs(name=nil, &block) + prefix = (!name.is_a?(Hash) and name) ? "./groups/#{name}" : "groups" + Proxy.new(connection, prefix, name, ::Ghee::GitLab::OrgTranslator.new(:repo), &block) + end + end + end +end + diff --git a/lib/ghee/gitlab/api/translators/org_translator.rb b/lib/ghee/gitlab/api/translators/org_translator.rb new file mode 100644 index 0000000..68cf816 --- /dev/null +++ b/lib/ghee/gitlab/api/translators/org_translator.rb @@ -0,0 +1,14 @@ +class Ghee + module GitLab + class OrgTranslator < Ghee::ApiTranslator + def translate_hash(data) + new_user = {} + new_user['login'] = data['path'] + new_user['id'] = data['id'] + new_user['description'] = data['description'] + + new_user + end + end + end +end From a12e62a5cd5d7e96488fe47ae9015bbdfbd54083 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 13 Dec 2015 01:26:00 -0800 Subject: [PATCH 19/23] Add user type --- lib/ghee/gitlab/api/translators/user_translator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ghee/gitlab/api/translators/user_translator.rb b/lib/ghee/gitlab/api/translators/user_translator.rb index a91f195..89d97aa 100644 --- a/lib/ghee/gitlab/api/translators/user_translator.rb +++ b/lib/ghee/gitlab/api/translators/user_translator.rb @@ -8,6 +8,7 @@ def translate_hash(data) new_user['avatar_url'] = data['avatar_url'] new_user['name'] = data['name'] new_user['email'] = data['email'] if data['email'] + new_user['type'] = 'User' new_user end end From 515604763b5745aec2a8818b828d95eb7c240bea Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 13 Dec 2015 11:02:14 -0800 Subject: [PATCH 20/23] Add repo permissions using access level checks --- lib/ghee/gitlab.rb | 1 + .../gitlab/api/translators/access_levels.rb | 11 +++++ .../api/translators/assignee_translator.rb | 8 +-- .../gitlab/api/translators/repo_translator.rb | 49 ++++++++++++++++++- 4 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 lib/ghee/gitlab/api/translators/access_levels.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index 37a8a29..a30cfa0 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -37,6 +37,7 @@ module API #require 'ghee/gitlab/api/contents' #require 'ghee/gitlab/api/members' +require 'ghee/gitlab/api/translators/access_levels' require 'ghee/gitlab/api/translators/assignee_translator' require 'ghee/gitlab/api/translators/commit_translator' require 'ghee/gitlab/api/translators/org_translator' diff --git a/lib/ghee/gitlab/api/translators/access_levels.rb b/lib/ghee/gitlab/api/translators/access_levels.rb new file mode 100644 index 0000000..a42dfc7 --- /dev/null +++ b/lib/ghee/gitlab/api/translators/access_levels.rb @@ -0,0 +1,11 @@ +class Ghee + module GitLab + class AccessLevels + GUEST = 10 + REPORTER = 20 + DEVELOPER = 30 + MASTER = 40 + OWNER = 50 + end + end +end diff --git a/lib/ghee/gitlab/api/translators/assignee_translator.rb b/lib/ghee/gitlab/api/translators/assignee_translator.rb index bd8c5c5..af225ce 100644 --- a/lib/ghee/gitlab/api/translators/assignee_translator.rb +++ b/lib/ghee/gitlab/api/translators/assignee_translator.rb @@ -1,19 +1,13 @@ class Ghee module GitLab class AssigneeTranslator < Ghee::ApiTranslator - GUEST = 10 - REPORTER = 20 - DEVELOPER = 30 - MASTER = 40 - OWNER = 50 - def translate_hash(data) new_user = {} new_user['id'] = data['id'] new_user['login'] = data['username'] new_user['avatar_url'] = data['avatar_url'] new_user['type'] = 'user' - new_user['site_admin'] = data['access_level'].to_i > DEVELOPER + new_user['site_admin'] = data['access_level'].to_i > ::Ghee::GitLab::AccessLevels::DEVELOPER new_user end end diff --git a/lib/ghee/gitlab/api/translators/repo_translator.rb b/lib/ghee/gitlab/api/translators/repo_translator.rb index a508f5d..9a17f2e 100644 --- a/lib/ghee/gitlab/api/translators/repo_translator.rb +++ b/lib/ghee/gitlab/api/translators/repo_translator.rb @@ -3,13 +3,58 @@ module GitLab class RepoTranslator < Ghee::ApiTranslator def translate_hash(input) output = {} + output['name'] = input['name'] output['full_name'] = input['path_with_namespace'] output['private'] = !input['public'] output['ssh_url'] = input['ssh_url_to_repo'] output['html_url'] = input['web_url'] output['has_issues'] = input['issues_enabled'] - # This is only available in GitLab 8.3 - output['open_issues_count'] = input.fetch('issues_enabled', 0) + + output['permissions'] = {} + + # XXX Project owners are not considered project members, so checking + # the permissions is not adequate. + admin_access = false + push_access = false + pull_access = false + + # Permissions do not come standard in older versions of GitLab + if input['permissions'] + puts input['permissions'] + group_perms = input['permissions']['group_access'] + project_perms = input['permissions']['project_access'] + + if group_perms + level = group_perms['access_level'].to_i + admin_access = level >= ::Ghee::GitLab::AccessLevels::MASTER + push_access = level >= ::Ghee::GitLab::AccessLevels::DEVELOPER + pull_access = level >= ::Ghee::GitLab::AccessLevels::DEVELOPER + end + + if project_perms + level = project_perms['access_level'].to_i + admin_access |= level >= ::Ghee::GitLab::AccessLevels::MASTER + push_access |= level >= ::Ghee::GitLab::AccessLevels::DEVELOPER + pull_access |= level >= ::Ghee::GitLab::AccessLevels::DEVELOPER + end + end + + output['permissions']['admin'] = admin_access + output['permissions']['push'] = push_access + output['permissions']['pull'] = pull_access + + output['owner'] = {} + + # Projects belonging to a group do not have an owner but do have + # namespace + if input['owner'] + output['owner']['login'] = input['owner']['username'] + elsif input['namespace'] + output['owner']['login'] = input['namespace']['path'] + end + + # This is only available in GitLab 8.3 + output['open_issues_count'] = input.fetch('open_issues_count', 0) output end end From 8350f38c2c8fd3e9eccc442380942b4714c7cc92 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 13 Dec 2015 11:04:43 -0800 Subject: [PATCH 21/23] Add support for GitLab labels --- lib/ghee/gitlab.rb | 2 +- lib/ghee/gitlab/api/labels.rb | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/ghee/gitlab/api/labels.rb diff --git a/lib/ghee/gitlab.rb b/lib/ghee/gitlab.rb index a30cfa0..20fa374 100644 --- a/lib/ghee/gitlab.rb +++ b/lib/ghee/gitlab.rb @@ -21,7 +21,7 @@ module API require 'ghee/gitlab/api/milestones' require 'ghee/gitlab/api/orgs' #require 'ghee/gitlab/api/git_data' -#require 'ghee/gitlab/api/labels' +require 'ghee/gitlab/api/labels' #require 'ghee/gitlab/api/hooks' #require 'ghee/gitlab/api/collaborators' #require 'ghee/gitlab/api/forks' diff --git a/lib/ghee/gitlab/api/labels.rb b/lib/ghee/gitlab/api/labels.rb new file mode 100644 index 0000000..7fc8b4f --- /dev/null +++ b/lib/ghee/gitlab/api/labels.rb @@ -0,0 +1,37 @@ +class Ghee + + # API module encapsulates all of API endpoints + # implemented thus far + # + module API + + # The Repos module handles all of the Github Repo + # API endpoints + # + module Repos + + module Labels + class Proxy < ::Ghee::ResourceProxy + end + end + + # Gists::Proxy inherits from Ghee::Proxy and + # enables defining methods on the proxy object + # + class Proxy < ::Ghee::ResourceProxy + + # Get labels for a repo + # + # id - Number get a specific label (optional) + # + # Returns json + # + def labels(number=nil, params={}) + params = number if number.is_a?Hash + prefix = (!number.is_a?(Hash) and number) ? "#{path_prefix}/labels/#{number}" : "#{path_prefix}/labels" + Ghee::API::Repos::Labels::Proxy.new(connection, prefix, nil, params) + end + end + end + end +end From cd50b82126a14db145442a1e3b9276f9da188b20 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 17 Dec 2015 07:30:30 -0800 Subject: [PATCH 22/23] Translate pagination results --- .ruby-version | 2 +- lib/ghee/resource_proxy.rb | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.ruby-version b/.ruby-version index cd57a8b..c043eea 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.5 +2.2.1 diff --git a/lib/ghee/resource_proxy.rb b/lib/ghee/resource_proxy.rb index 3d7f136..56af337 100644 --- a/lib/ghee/resource_proxy.rb +++ b/lib/ghee/resource_proxy.rb @@ -74,11 +74,14 @@ def subject @block.call(req)if @block end - if @api_translator - @api_translator.translate_data(response.body) - else - response.body - end + translate_body(response.body) + end + + def translate_body(body) + if @api_translator + @api_translator.translate_data(body) + else + body end end @@ -100,9 +103,9 @@ def paginate(options) end if @subject.nil? - @subject = response.body + @subject = translate_body(response.body) else - @subject = @subject.concat response.body + @subject = @subject.concat translate_body(response.body) end parse_link_header response.headers.delete("link") From 957c1a0d4ec2266bf87f0a7ca1a51280a1a5d717 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 17 Dec 2015 07:38:07 -0800 Subject: [PATCH 23/23] Fix typo --- lib/ghee/resource_proxy.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ghee/resource_proxy.rb b/lib/ghee/resource_proxy.rb index 56af337..e10be55 100644 --- a/lib/ghee/resource_proxy.rb +++ b/lib/ghee/resource_proxy.rb @@ -75,6 +75,7 @@ def subject end translate_body(response.body) + end end def translate_body(body)