Class: Gemfury::Client

Inherits:
Object
  • Object
show all
Includes:
Filters
Defined in:
lib/gemfury/client.rb,
lib/gemfury/client/filters.rb,
lib/gemfury/client/middleware.rb

Defined Under Namespace

Modules: Filters Classes: Handle503, ParseJson

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Creates a new API


7
8
9
10
11
12
# File 'lib/gemfury/client.rb', line 7

def initialize(options={})
  options = Gemfury.options.merge(options)
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#account_infoObject

Get the information for the current account


15
16
17
18
19
# File 'lib/gemfury/client.rb', line 15

def 
  ensure_ready!(:authorization)
  response = connection.get('users/me')
  checked_response_body(response)
end

#add_collaborator(login, options = {}) ⇒ Object

Add a collaborator to the account


85
86
87
88
89
90
# File 'lib/gemfury/client.rb', line 85

def add_collaborator(, options = {})
  ensure_ready!(:authorization)
  url = "collaborators/#{escape()}"
  response = connection.put(url, options)
  checked_response_body(response)
end

#get_access_token(*args) ⇒ Object

LEGACY: Authentication token via email/password


66
67
68
# File 'lib/gemfury/client.rb', line 66

def get_access_token(*args)
  (*args)['access_token']
end

#git_rebuild(repo, options = {}) ⇒ Object

Rebuild Git repository package


122
123
124
125
126
127
# File 'lib/gemfury/client.rb', line 122

def git_rebuild(repo, options = {})
  ensure_ready!(:authorization)
  url = "#{git_repo_path(repo)}/builds"
  api = connection(:api_format => :text)
  checked_response_body(api.post(url, options))
end

#git_repos(options = {}) ⇒ Object

List Git repos for this account


101
102
103
104
105
# File 'lib/gemfury/client.rb', line 101

def git_repos(options = {})
  ensure_ready!(:authorization)
  response = connection.get(git_repo_path, options)
  checked_response_body(response)
end

#git_reset(repo, options = {}) ⇒ Object

Reset repository to initial state


115
116
117
118
119
# File 'lib/gemfury/client.rb', line 115

def git_reset(repo, options = {})
  ensure_ready!(:authorization)
  response = connection.delete(git_repo_path(repo), options)
  checked_response_body(response)
end

#git_update(repo, options = {}) ⇒ Object

Update repository name and settings


108
109
110
111
112
# File 'lib/gemfury/client.rb', line 108

def git_update(repo, options = {})
  ensure_ready!(:authorization)
  response = connection.patch(git_repo_path(repo), options)
  checked_response_body(response)
end

#list(options = {}) ⇒ Object

List available gems


43
44
45
46
47
# File 'lib/gemfury/client.rb', line 43

def list(options = {})
  ensure_ready!(:authorization)
  response = connection.get('gems', options)
  checked_response_body(response)
end

#list_collaborators(options = {}) ⇒ Object

List collaborators for this account


78
79
80
81
82
# File 'lib/gemfury/client.rb', line 78

def list_collaborators(options = {})
  ensure_ready!(:authorization)
  response = connection.get('collaborators', options)
  checked_response_body(response)
end

#login(email, password, opts = {}) ⇒ Object

Get authentication info via email/password


71
72
73
74
75
# File 'lib/gemfury/client.rb', line 71

def (email, password, opts = {})
  ensure_ready!
  opts = opts.merge(:email => email, :password => password)
  checked_response_body(connection.post('access_token', opts))
end

#push_gem(gem_file, options = {}) ⇒ Object

Uploading a gem file


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gemfury/client.rb', line 22

def push_gem(gem_file, options = {})
  ensure_ready!(:authorization)

  # Generate upload link
  api2 = connection(:api_version => 2)
  response = api2.post('uploads')
  checked_response_body(response)

  # Upload to S3
  upload = response.body['upload']
  id, s3url = upload['id'], upload['blob']['put']
  response = s3_put_file(s3url, gem_file)
  checked_response_body(response)

  # Notify Gemfury that the upload is ready
  options[:name] ||= File.basename(gem_file.path)
  response = api2.put("uploads/#{id}", options)
  checked_response_body(response)
end

#remove_collaborator(login, options = {}) ⇒ Object

Remove a collaborator to the account


93
94
95
96
97
98
# File 'lib/gemfury/client.rb', line 93

def remove_collaborator(, options = {})
  ensure_ready!(:authorization)
  url = "collaborators/#{escape()}"
  response = connection.delete(url, options)
  checked_response_body(response)
end

#versions(name, options = {}) ⇒ Object

List versions for a gem


50
51
52
53
54
55
# File 'lib/gemfury/client.rb', line 50

def versions(name, options = {})
  ensure_ready!(:authorization)
  url = "gems/#{escape(name)}/versions"
  response = connection.get(url, options)
  checked_response_body(response)
end

#yank_version(name, version, options = {}) ⇒ Object

Delete a gem version


58
59
60
61
62
63
# File 'lib/gemfury/client.rb', line 58

def yank_version(name, version, options = {})
  ensure_ready!(:authorization)
  url = "gems/#{escape(name)}/versions/#{escape(version)}"
  response = connection.delete(url, options)
  checked_response_body(response)
end