packagecloud-ruby 0.2.17 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e8f650dbc96aa88992fc0dda27623c8719d18c7
4
- data.tar.gz: ef502f707b27a9a07f2530fb8e2deb41c3bc00f7
3
+ metadata.gz: 7d5b9cfbb4fa58fd4513b51b77128a5f79b09cec
4
+ data.tar.gz: 79c30b70c7404f03a2162def26a4c7de879e5ba0
5
5
  SHA512:
6
- metadata.gz: d02c15ff34c1d54263bb1fc52acddb1a05f09694eb175076e218e35f5051410b4939f48f20adf5748cd3266f38dbc1369764994ec168514288e8674950ef902b
7
- data.tar.gz: 4eafaf179abc1380cf65756f3a2b1ac853c3f4d2d497ba42be3109405fba18d82015bf01fc18e1fb9f667a8a624656a49a5e086ea3ee1dd1ca1322e447615f36
6
+ metadata.gz: ed77f5de56f89489e43296cfbf581bcb9abb713d4020403494a5db9f4931b01e96d7650b14ebb44bdafb7c9ff4051f7b659694a55905c7dfbf07a6da7dfc433a
7
+ data.tar.gz: 759d2175cb37074adf17231af1cfd198f6af203420a57fcdb25771a894e39d2073dff0dbc0a295366354c4a71c2c187305d24b3ea5bb6a51066695491256359c
data/README.md CHANGED
@@ -22,13 +22,22 @@ Ruby library for communicating with the [packagecloud.io](https://packagecloud.i
22
22
  gem install packagecloud-ruby
23
23
  ```
24
24
 
25
+ ## Getting your API token
26
+
27
+ Login to [packagecloud.io](https://packagecloud.io) and
28
+ go to your [Account Settings](https://packagecloud.io/api_token) to see your API token.
29
+
25
30
  ## Creating a Client
26
31
 
32
+ Note that you should not use the email address associated with your
33
+ [packagecloud.io](https://packagecloud.io) account when accessing the API.
34
+ Please use your username on the site.
35
+
27
36
  ```ruby
28
37
  require 'packagecloud'
29
38
 
30
- # Create a client
31
- credentials = Packagecloud::Credentials.new("joedamato", "test_token")
39
+ # Create a client using your username and API token
40
+ credentials = Packagecloud::Credentials.new("joedamato", "my_api_token")
32
41
  @client = Packagecloud::Client.new(credentials)
33
42
 
34
43
  ```
@@ -54,12 +63,14 @@ Ruby library for communicating with the [packagecloud.io](https://packagecloud.i
54
63
 
55
64
  ### Distributions
56
65
 
66
+ This is the list of currently [supported distributions](https://packagecloud.io/docs#os_distro_version).
67
+
57
68
  ```ruby
58
69
  # Get all distributions
59
70
  distros = @client.distributions
60
71
 
61
72
  # Looking up a distribution id by name
62
- id = @client.find_distribution_id("centos/6") # returns 12
73
+ id = @client.find_distribution_id("el/6") # returns 27
63
74
  ```
64
75
 
65
76
  ### Repositories
@@ -76,17 +87,31 @@ Ruby library for communicating with the [packagecloud.io](https://packagecloud.i
76
87
 
77
88
  ```
78
89
 
90
+ When specifiying your repository name, you should use just the name and not
91
+ the fully qualified name (fqname).
92
+
93
+ For example:
94
+
95
+ ```ruby
96
+ # INCORRECT: this should just be "my_repo"
97
+ repo = @client.repository("user/my_repo")
98
+ ```
99
+
79
100
  ### Packages
80
101
 
81
102
  ```ruby
82
- # Create Packages (takes IO object for file)
83
- gem_package = Package.new(open("rails-4.0.0.gem"))
84
- rpm_package = Package.new(open("libcurl-0.1.2.rpm"), 12) # 12 being the distribution id for centos/6, for example
103
+ # Create RPM Packages (takes IO object for file)
104
+ distro_id = @client.find_distribution_id("el/6")
105
+ rpm_package = Packagecloud::Package.new(open("libcurl-0.1.2.rpm"), distro_id)
106
+
107
+ # Creating gem Packages (no distribution required)
108
+ gem_package = Packagecloud::Package.new(open("rails-4.0.0.gem"))
85
109
 
86
110
  # Creating source Packages
111
+ distro_id = @client.find_distribution_id("ubuntu/trusty")
87
112
  source_files = { "jake_1.0.orig.tar.bz2" => open("/path/jake_1.0.orig.tar.bz2"),
88
113
  "jake_1.0-7.debian.tar.gz" => open("/path/jake_1.0-7.debian.tar.gz") }
89
- dsc_package = Package.new("jake_1.0-7.dsc", 20, source_files)
114
+ dsc_package = Packagecloud::Package.new("jake_1.0-7.dsc", distro_id, source_files)
90
115
 
91
116
  # Upload Packages
92
117
  @client.put_package("test_repo", gem_package)
@@ -96,6 +121,6 @@ Ruby library for communicating with the [packagecloud.io](https://packagecloud.i
96
121
 
97
122
  ## Copyright
98
123
 
99
- Copyright (c) 2014 Computology, LLC
124
+ Copyright (c) 2014-2015 Computology, LLC
100
125
 
101
126
  See LICENSE.txt for details.
@@ -24,6 +24,22 @@ module Packagecloud
24
24
  end
25
25
  end
26
26
 
27
+ class InvalidRepoNameException < StandardError
28
+ attr_reader :object
29
+
30
+ def initialize(object = nil)
31
+ @object = object
32
+ end
33
+ end
34
+
35
+ class InvalidUsernameException < StandardError
36
+ attr_reader :object
37
+
38
+ def initialize(object = nil)
39
+ @object = object
40
+ end
41
+ end
42
+
27
43
  class Client
28
44
  attr_reader :connection
29
45
  attr_reader :credentials
@@ -54,6 +70,7 @@ module Packagecloud
54
70
  end
55
71
 
56
72
  def repository(repo)
73
+ assert_valid_repo_name(repo)
57
74
  response = get("/api/v1/repos/#{username}/#{repo}.json")
58
75
  parsed_json_result(response)
59
76
  end
@@ -64,6 +81,7 @@ module Packagecloud
64
81
  end
65
82
 
66
83
  def create_repository(repo, private=false)
84
+ assert_valid_repo_name(repo)
67
85
  privacy = private ? 1 : 0
68
86
  body = { "repository" => { "name" => repo, "private" => privacy.to_s } }
69
87
  response = post("/api/v1/repos.json", body.to_json)
@@ -71,6 +89,7 @@ module Packagecloud
71
89
  end
72
90
 
73
91
  def package_contents(repo, package)
92
+ assert_valid_repo_name(repo)
74
93
  url = "/api/v1/repos/#{username}/#{repo}/packages/contents.json"
75
94
 
76
95
  mixed_msg = MIME::Multipart::FormData.new
@@ -85,6 +104,8 @@ module Packagecloud
85
104
  end
86
105
 
87
106
  def put_package(repo, package)
107
+ assert_valid_repo_name(repo)
108
+
88
109
  url = "/api/v1/repos/#{username}/#{repo}/packages.json"
89
110
 
90
111
  mixed_msg = MIME::Multipart::FormData.new
@@ -127,6 +148,15 @@ module Packagecloud
127
148
  end
128
149
 
129
150
  private
151
+ def assert_valid_repo_name(repo)
152
+ if repo.include?("/")
153
+ raise InvalidRepoNameException.new("The repo name: #{repo} is " \
154
+ "invalid. It looks like you are " \
155
+ "using the fully qualified name " \
156
+ "(fqname) instead of just the " \
157
+ "repo name. Please try again.")
158
+ end
159
+ end
130
160
 
131
161
  def assert_compatible_version
132
162
  result = gem_version
@@ -216,4 +246,4 @@ module Packagecloud
216
246
  end
217
247
 
218
248
  end
219
- end
249
+ end
@@ -6,6 +6,13 @@ module Packagecloud
6
6
  def initialize(username, token)
7
7
  @username = username
8
8
  @token = token
9
+ if @username.include?("@")
10
+ raise InvalidUsernameException.new("Sorry, looks like you may have " \
11
+ "tried to use an email address " \
12
+ "instead of your packagecloud.io " \
13
+ "username. Please use your " \
14
+ "username instead!")
15
+ end
9
16
  end
10
17
  end
11
- end
18
+ end
@@ -1,7 +1,7 @@
1
1
  module Packagecloud
2
2
  MAJOR_VERSION = "0"
3
3
  MINOR_VERSION = "2"
4
- PATCH_VERSION = "17"
4
+ PATCH_VERSION = "19"
5
5
 
6
6
  VERSION = [MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION].join(".")
7
7
  end
@@ -133,6 +133,12 @@ describe Packagecloud do
133
133
  expect(result.response["name"]).to eq("test_repo")
134
134
  end
135
135
 
136
+ it "should raise if the repo name is invalid" do
137
+ expect do
138
+ result = @client.repository("hi/test_repo")
139
+ end.to raise_error(InvalidRepoNameException)
140
+ end
141
+
136
142
  it "GET /api/v1/repos/joedamato/invalid_repo.json (invalid repo)" do
137
143
  result = @client.repository("invalid_repo")
138
144
  expect(result.succeeded).to be_falsey
@@ -143,6 +149,12 @@ describe Packagecloud do
143
149
  expect($request["User-Agent"]).to eq("packagecloud-ruby #{Packagecloud::VERSION}/test_client")
144
150
  end
145
151
 
152
+ it "should raise if the username has an @ in it" do
153
+ expect do
154
+ credentials = Credentials.new("hi@test.com", "test_token")
155
+ end.to raise_error(InvalidUsernameException)
156
+ end
157
+
146
158
  it "should raise if api has advanced too far" do
147
159
  current = Packagecloud::MINOR_VERSION
148
160
  Packagecloud::MINOR_VERSION = "1"
@@ -177,7 +189,6 @@ describe Packagecloud do
177
189
  end
178
190
 
179
191
  describe "find_distribution_id" do
180
-
181
192
  it "should find ubuntu/breezy" do
182
193
  id = @client.find_distribution_id("ubuntu/breezy")
183
194
  expect(id).to be(3)
@@ -199,6 +210,4 @@ describe Packagecloud do
199
210
  }.to raise_error
200
211
  end
201
212
  end
202
-
203
-
204
213
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packagecloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Damato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-02 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.4.1
189
+ rubygems_version: 2.4.4
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: library for interacting with packagecloud.io