Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.5
2.2.1
21 changes: 2 additions & 19 deletions lib/ghee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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
3 changes: 1 addition & 2 deletions lib/ghee/api/authorizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions lib/ghee/api/collaborators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/ghee/api/commit_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions lib/ghee/api/commit_statuses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/ghee/api/commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 3 additions & 16 deletions lib/ghee/api/contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 5 additions & 30 deletions lib/ghee/api/downloads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions lib/ghee/api/emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ghee/api/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions lib/ghee/api/followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/ghee/api/forks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 7 additions & 10 deletions lib/ghee/api/gists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -31,39 +30,39 @@ def comments(id = nil)
# Returns true/false
#
def star
connection.put("#{path_prefix}/star").status == 204
raise NotImplemented
end

# Unstar a gist
#
# Returns true/false
#
def unstar
connection.delete("#{path_prefix}/star").status == 204
raise NotImplemented
end

# Returns whether gist is starred
#
# Returns true/false
#
def starred?
connection.get("#{path_prefix}/star").status == 204
raise NotImplemented
end

# Get public gists
#
# Returns json
#
def public
connection.get("#{path_prefix}/public").body
raise NotImplemented
end

# Get starred gists
#
# Returns json
#
def starred
connection.get("#{path_prefix}/starred").body
raise NotImplemented
end

end
Expand All @@ -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
Expand Down
Loading