cdnconnect-api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -13
  3. data/lib/cdnconnect_api.rb +37 -49
  4. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6d3d3255939e60f875633fb33fc3d0a5f2a52e2
4
- data.tar.gz: 58ec54989764b9eb02b4d59802caddbda326dffb
3
+ metadata.gz: b1f2158a5e22b91680429d6bff92c989683706a8
4
+ data.tar.gz: 68128b30f4bead555cb4f951db73ffaf4afa1825
5
5
  SHA512:
6
- metadata.gz: 42d5a6ea40556f3dced79a275fb61be47b83446e3588ea83a54a8b2de7da9f94d87fcf8d49219fd778c419750005b8af5e931f5920b0f3c5989063772fbb064a
7
- data.tar.gz: 8369b89dc1e239689322b7df3d22ba0c5c65b97efa8701e4d1767520505d375e390b4f9ff0ae5fd161f002e5f9a149d16b822f1b8828772a6fb35cec6a1d6c64
6
+ metadata.gz: 877dd452661d8b2f24de5e3485facca42402bccf2a4c6238faebd7ff4b8e64a3d563f5a584641b56f4b337f42504c0919b6091f3844ef27d58812ba5eeba31bf
7
+ data.tar.gz: 4d78036142f1e38f13f089d351cbecf4df88a17eaf8a34e971512276fabd3e137a66f30ef474ea81878b4574adf06fa6c6dd8d3e36cf689e8700087012d6c302
data/README.md CHANGED
@@ -1,20 +1,22 @@
1
- # CDN Connect API Ruby Client, v0.0.2
1
+ # CDN Connect API Ruby Client, v0.1.0
2
2
 
3
- The CDN Connect API Ruby Client makes it easier to upload files and interact with
4
- our API. Most interactions with CDN Connect APIs require users to authorize applications via OAuth 2.0. This library simplifies the communication with CDN Connect even further allowing you
5
- to easily upload files and get information with only a few lines of code.
3
+ CDN Connect makes it easier to manage production assets for teams of developers and designers, all while serving files from a fast content delivery network. Features include image optimization, resizing, cropping, filters, etc. The CDN Connect API Ruby Client makes it easier to upload files and interact with the API. Most interactions with CDN Connect APIs require users to authorize applications via OAuth 2.0. This library simplifies the communication with CDN Connect even further allowing you to easily upload files and get information with only a few lines of code.
4
+
5
+ [View the full CDN Connect API documentation](http://api.cdnconnect.com/)
6
6
 
7
7
  ## Install
8
8
 
9
- $ sudo gem install cdnconnect-api
9
+ $ gem install cdnconnect-api
10
10
 
11
11
  [RubyGems.org: cdnconnect-api](https://rubygems.org/gems/cdnconnect-api)
12
12
 
13
+
13
14
  ## API Key
14
15
 
15
16
  An API Key can be created for a specific app within your CDN Connect's account. Sign into your account and go to the "API Key" tab for the app you want to interact with. Next click "Add API Key" and use this value when creating a new API client within the code. The API Key can be revoked
16
17
  by you at any time and numerous keys can be created.
17
18
 
19
+
18
20
  ## Example Usage
19
21
 
20
22
  # Initialize the CDN Connect API client
@@ -30,18 +32,22 @@ by you at any time and numerous keys can be created.
30
32
  # "Woot!"
31
33
  end
32
34
 
35
+
33
36
  ## Get Object Data
34
37
 
35
- An object can be either a file or a folder. Pass the `get` method the `url` you want to receive data about.
38
+ Following the [API documentation](http://api.cdnconnect.com/), you can use these methods to build a requests and return an APIResponse object.
39
+
40
+ * `get`: GET Request. Used when needing to just read data.
41
+ * `post`: POST Request. Used when creating data.
42
+ * `put`: PUT Request. Used when updating data.
43
+ * `delete`: DELETE Request. Used when deleting data.
44
+
45
+ Each of these methods take one parameter which is the API path you want to request. Depending on which method you use, it will send the request with the correct HTTP verb.
36
46
 
37
47
  # Get file information
38
- response = api_client.get(:url => 'demo.cdnconnect.com/images/meowzers.jpg')
48
+ response = api_client.get('demo.cdnconnect.com/images/meowzers.jpg')
39
49
  puts response.results['data']['name'] #=> "meowzers.jpg"
40
50
 
41
- # Get folder information
42
- response = api_client.get(:url => 'demo.cdnconnect.com/images')
43
- puts response.results['data']['name'] #=> "images"
44
-
45
51
 
46
52
  ## Response Object
47
53
 
@@ -65,8 +71,7 @@ All responses will be structured the same with both a `results` and `msgs` objec
65
71
  "msgs":[]
66
72
  }
67
73
 
68
- The `results` object contains the guts of the information your looking for, and the `msgs` object contains an array of messages which can represent errors, warnings and information. The `results` object can be null, or it can contain many objects within it. Each response can have different data within `results` object and `msgs` object. In the case above, the `results` object contains the key `data`, and within the `data` object it contains summary information of the images folder.
69
-
74
+ Be sure to view the [API documentation](http://api.cdnconnect.com/) describing what each response object will contain depending on the API resource.
70
75
 
71
76
 
72
77
  ## Support
@@ -23,7 +23,7 @@ module CDNConnect
23
23
  class APIClient
24
24
 
25
25
  @@application_name = 'cdnconnect-api-ruby'
26
- @@application_version = '0.1.0'
26
+ @@application_version = '0.1.1'
27
27
  @@api_host = 'https://api.cdnconnect.com'
28
28
  @@user_agent = @@application_name + ' v' + @@application_version
29
29
 
@@ -37,9 +37,6 @@ module CDNConnect
37
37
  # - <code>:api_key</code> -
38
38
  # An API Key (commonly known as an access_token) which was previously
39
39
  # created within CDN Connect's account for a specific app.
40
- # - <code>:response_format</code> -
41
- # How data should be formatted on the response. Possible values for
42
- # include application/json, application/xml. JSON is the default.
43
40
  # - <code>:client_id</code> -
44
41
  # A unique identifier issued to the client to identify itself to CDN Connect's
45
42
  # authorization server. This is issued by CDN Connect to external clients.
@@ -61,6 +58,8 @@ module CDNConnect
61
58
  # The redirection URI used in the initial request.
62
59
  # - <code>:access_token</code> -
63
60
  # The current access token for this client, also known as the API Key.
61
+ # - <code>:debug</code> -
62
+ # Print out any debugging information. Default is false.
64
63
  def initialize(options={})
65
64
  # Normalize key to String to allow indifferent access.
66
65
  options = options.inject({}) { |accu, (k, v)| accu[k.to_s] = v; accu }
@@ -74,7 +73,7 @@ module CDNConnect
74
73
  @redirect_uri = options["redirect_uri"]
75
74
  options["access_token"] = options["access_token"] || options["api_key"] # both work
76
75
  @access_token = options["access_token"]
77
- @response_format = options["response_format"] || 'application/json'
76
+ @debug = options["debug"] || false
78
77
  @prefetched_upload_urls = {}
79
78
 
80
79
  # Create the OAuth2 client which will be used to authorize the requests
@@ -93,12 +92,10 @@ module CDNConnect
93
92
  # Executes a GET request to an API URL and returns a response object.
94
93
  # GET requests are used when reading data.
95
94
  #
96
- # @param url [String] The API URL to send a GET request to.
95
+ # @param path [String] The API path to send the GET request to.
97
96
  # @return [APIResponse] A response object with helper methods to read the response.
98
- def get(url)
99
- options[:path] = url
100
- options[:method] = 'GET'
101
- return self.fetch(options)
97
+ def get(path)
98
+ return self.fetch(:path => path, :method => 'GET')
102
99
  end
103
100
 
104
101
 
@@ -106,12 +103,10 @@ module CDNConnect
106
103
  # Executes a POST request to an API URL and returns a response object.
107
104
  # POST requests are used when creating data.
108
105
  #
109
- # @param url [String] The API URL to send a POST request to.
106
+ # @param path [String] The API path to send the POST request to.
110
107
  # @return [APIResponse] A response object with helper methods to read the response.
111
- def post(url)
112
- options[:path] = url
113
- options[:method] = 'POST'
114
- return self.fetch(options)
108
+ def post(path)
109
+ return self.fetch(:path => path, :method => 'POST')
115
110
  end
116
111
 
117
112
 
@@ -119,12 +114,10 @@ module CDNConnect
119
114
  # Executes a PUT request to an API URL and returns a response object.
120
115
  # PUT requests are used when updating data.
121
116
  #
122
- # @param url [String] The API URL to send a GET request to.
117
+ # @param path [String] The API path to send the POST request to.
123
118
  # @return [APIResponse] A response object with helper methods to read the response.
124
- def post(url)
125
- options[:path] = url
126
- options[:method] = 'POST'
127
- return self.fetch(options)
119
+ def put(path)
120
+ return self.fetch(:path => path, :method => 'PUT')
128
121
  end
129
122
 
130
123
 
@@ -132,12 +125,10 @@ module CDNConnect
132
125
  # Executes a DELETE request to an API URL and returns a response object.
133
126
  # DELETE requests are used when (you guessed it) deleting data.
134
127
  #
135
- # @param url [String] The API URL to send a DELETE request to.
128
+ # @param path [String] The API path to send the DELETE request to.
136
129
  # @return [APIResponse] A response object with helper methods to read the response.
137
130
  def delete(url)
138
- options[:path] = url
139
- options[:method] = 'DELETE'
140
- return self.fetch(options)
131
+ return self.fetch(:path => path, :method => 'DELETE')
141
132
  end
142
133
 
143
134
 
@@ -159,6 +150,9 @@ module CDNConnect
159
150
  # are not provided then you must use the url option.
160
151
  # - <code>:source_file_local_path</code> -
161
152
  # A string of a source file's local paths to upload.
153
+ # - <code>:response_format</code> -
154
+ # How data should be formatted on the response. Possible values
155
+ # include json (default) or xml.
162
156
  # @return [APIResponse] A response object with helper methods to read the response.
163
157
  def upload(options={})
164
158
  # Make sure we've got good data before starting the upload
@@ -198,6 +192,9 @@ module CDNConnect
198
192
  end
199
193
 
200
194
  # Kick it off!
195
+ if @debug
196
+ puts 'upload, source: ' + options[:source_file_local_path] + ', destination: ' + options[:destination_folder_url]
197
+ end
201
198
  api_response = conn.post upload_url, post_data
202
199
 
203
200
  # Woot! Convert the response to our model and see what's up
@@ -290,11 +287,19 @@ module CDNConnect
290
287
 
291
288
  path = nil
292
289
  if destination_folder_url != nil
293
- path = '/v1/' + destination_folder_url + '/upload'
290
+ path = destination_folder_url + '/upload'
294
291
  else
295
292
  path = generate_obj_path(options) + '/upload'
296
293
  end
297
294
 
295
+ # Default Content-Type is application/json with a .json extension
296
+ response_extension = 'json'
297
+ if options[:response_format] == 'xml'
298
+ response_extension = 'xml'
299
+ end
300
+
301
+ path = '/v1/' + path + '.' + response_extension
302
+
298
303
  i = 1
299
304
  begin
300
305
  response = self.fetch(:path => path)
@@ -333,7 +338,7 @@ module CDNConnect
333
338
  raise ArgumentError, "missing url or both app_id and obj_id"
334
339
  end
335
340
 
336
- return '/v1/' + path
341
+ return path
337
342
  end
338
343
 
339
344
 
@@ -346,23 +351,8 @@ module CDNConnect
346
351
  raise ArgumentError, 'missing api path'
347
352
  end
348
353
 
349
- options[:response_format] = options[:response_format] || @response_format
350
-
351
- headers = { 'User-Agent' => @@user_agent }
352
-
353
- # There are three possible response content-types: JSON, XML
354
- # Default Content-Type is application/json with a .json extension
355
- if options[:response_format] == 'application/xml'
356
- headers['Content-Type'] = 'application/xml'
357
- response_extension = 'xml'
358
- else
359
- options[:response_format] = 'application/json'
360
- headers['Content-Type'] = 'application/json'
361
- response_extension = 'json'
362
- end
363
- options[:headers] = headers
364
-
365
- options[:uri] = @@api_host + options[:path] + '.' + response_extension
354
+ options[:headers] = { 'User-Agent' => @@user_agent }
355
+ options[:uri] = @@api_host + options[:path]
366
356
  options[:url] = options[:uri]
367
357
  options[:method] = options[:method] || 'GET'
368
358
 
@@ -377,6 +367,10 @@ module CDNConnect
377
367
  # Prepare the data to be shipped in the request
378
368
  options = self.prepare(options)
379
369
 
370
+ if @debug
371
+ puts 'fetch: ' + options[:uri]
372
+ end
373
+
380
374
  begin
381
375
  # Send the request and get the response
382
376
  response = @client.fetch_protected_resource(options)
@@ -388,12 +382,6 @@ module CDNConnect
388
382
  end
389
383
 
390
384
  end
391
- # - <code>:code</code> -
392
- # The authorization code received from the authorization server.
393
- # - <code>:redirect_uri</code> -
394
- # The redirection URI used in the initial request.
395
- # - <code>:access_token</code> -
396
- # The current access token for this client, also known as the API Key.
397
385
 
398
386
 
399
387
  ##
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdnconnect-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bradley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-16 00:00:00.000000000 Z
11
+ date: 2013-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,11 +38,13 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.4.5
41
- description: The CDN Connect API Ruby Client makes it easier to upload files and interact
42
- with our API. Most interactions with CDN Connect APIs require users to authorize
43
- applications via OAuth 2.0. This library simplifies the communication with CDN Connect
44
- even further allowing you to easily upload files and get information with only a
45
- few lines of code.
41
+ description: CDN Connect makes it easier to manage production assets for teams of
42
+ developers and designers, all while serving files from a fast content delivery network.
43
+ Features include image optimization, resizing, cropping, filters, etc. The CDN Connect
44
+ API Ruby Client makes it easier to upload files and interact with the API. Most
45
+ interactions with CDN Connect APIs require users to authorize applications via OAuth
46
+ 2.0. This library simplifies the communication with CDN Connect even further allowing
47
+ you to easily upload files and get information with only a few lines of code.
46
48
  email: developer@cdnconnect.com
47
49
  executables: []
48
50
  extensions: []