cdnconnect-api 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1f2158a5e22b91680429d6bff92c989683706a8
4
- data.tar.gz: 68128b30f4bead555cb4f951db73ffaf4afa1825
3
+ metadata.gz: 87036814444c22863b8635b0d8004733180fe3c7
4
+ data.tar.gz: e570f55d47c36fda2ddb196e5371ec35b18178aa
5
5
  SHA512:
6
- metadata.gz: 877dd452661d8b2f24de5e3485facca42402bccf2a4c6238faebd7ff4b8e64a3d563f5a584641b56f4b337f42504c0919b6091f3844ef27d58812ba5eeba31bf
7
- data.tar.gz: 4d78036142f1e38f13f089d351cbecf4df88a17eaf8a34e971512276fabd3e137a66f30ef474ea81878b4574adf06fa6c6dd8d3e36cf689e8700087012d6c302
6
+ metadata.gz: a948d0f7bbdbdc95767ad1a5dc2bb1c033e0ef084951250b349816fe5c9682d56e0eadf0e90f5e3d7d85cac69453bf32e45d482cb39e937fcb6c9ec25f82a273
7
+ data.tar.gz: c9246b9728a2ea0b098f95b6075cd53133dd8eb8e8e202ebebc5f177418a12d0ee0dadb0cdacca17650d6e613c1493b728c9de5f599c4266af6dc552fce19b2c
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CDN Connect API Ruby Client, v0.1.0
1
+ # CDN Connect API Ruby Client, v0.1.2
2
2
 
3
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
4
 
@@ -17,7 +17,7 @@ An API Key can be created for a specific app within your CDN Connect's account.
17
17
  by you at any time and numerous keys can be created.
18
18
 
19
19
 
20
- ## Example Usage
20
+ ## Upload Example
21
21
 
22
22
  # Initialize the CDN Connect API client
23
23
  require 'cdnconnect_api'
@@ -33,43 +33,48 @@ by you at any time and numerous keys can be created.
33
33
  end
34
34
 
35
35
 
36
- ## Get Object Data
36
+ ## API Requests
37
37
 
38
38
  Following the [API documentation](http://api.cdnconnect.com/), you can use these methods to build a requests and return an APIResponse object.
39
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.
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
44
 
45
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.
46
46
 
47
- # Get file information
48
- response = api_client.get('demo.cdnconnect.com/images/meowzers.jpg')
49
- puts response.results['data']['name'] #=> "meowzers.jpg"
47
+ response = api_client.get('/v1/demo.cdnconnect.com/images/meowzers.jpg.json')
48
+ puts response.results['object']['name'] #=> "meowzers.jpg"
49
+
50
+ The path in the API request is broken down as:
51
+
52
+ * `/v1/` The API version, which must always prefix an API request path.
53
+ * `demo.cdnconnect.com/images/meowzers.jpg` The URL which you want to get information about.
54
+ * `.json` The response format, which can be `json` or `xml`.
50
55
 
51
56
 
52
57
  ## Response Object
53
58
 
54
59
  All responses will be structured the same with both a `results` and `msgs` object at the root level, such as:
55
60
 
56
- {
57
- "results":
58
- {
59
- "data":
60
- {
61
- "id": "bU1SS1JyvF9I",
62
- "status": 1,
63
- "name": "images",
64
- "created": "2013-03-12T17:02Z",
65
- "parent_id": "iF637hnbwI4G",
66
- "folder": true,
67
- "files": [],
68
- "folders": []
69
- }
70
- },
71
- "msgs":[]
72
- }
61
+ {
62
+ "results":
63
+ {
64
+ "object":
65
+ {
66
+ "id": "bU1SS1JyvF9I",
67
+ "status": 1,
68
+ "name": "images",
69
+ "created": "2013-03-12T17:02Z",
70
+ "parent_id": "iF637hnbwI4G",
71
+ "folder": true,
72
+ "files": [],
73
+ "folders": []
74
+ }
75
+ },
76
+ "msgs":[]
77
+ }
73
78
 
74
79
  Be sure to view the [API documentation](http://api.cdnconnect.com/) describing what each response object will contain depending on the API resource.
75
80
 
@@ -150,9 +150,6 @@ module CDNConnect
150
150
  # are not provided then you must use the url option.
151
151
  # - <code>:source_file_local_path</code> -
152
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.
156
153
  # @return [APIResponse] A response object with helper methods to read the response.
157
154
  def upload(options={})
158
155
  # Make sure we've got good data before starting the upload
@@ -292,13 +289,7 @@ module CDNConnect
292
289
  path = generate_obj_path(options) + '/upload'
293
290
  end
294
291
 
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
292
+ path = '/v1/' + path + '.json'
302
293
 
303
294
  i = 1
304
295
  begin
@@ -451,12 +442,7 @@ module CDNConnect
451
442
  def api_key
452
443
  @access_token
453
444
  end
454
-
455
-
456
- # @return [String]
457
- def response_format
458
- @response_format
459
- end
445
+
460
446
 
461
447
  end
462
448
 
@@ -31,16 +31,14 @@ module CDNConnect
31
31
  end
32
32
 
33
33
  def data()
34
- # Convert the response body depending on the response format
34
+ # Decode the response body from JSON into an object.
35
35
  # Keep the parsed data in an instance variable so we
36
36
  # don't keep parsing it every time we reference data()
37
37
  if @data == nil
38
38
  if format.include? 'application/json'
39
39
  @data = ActiveSupport::JSON.decode(body)
40
- elsif format.include? 'application/xml'
41
- @data = ActiveSupport::XML.decode(body)
42
40
  else
43
- raise "invalid data format"
41
+ raise "Data response type must be JSON"
44
42
  end
45
43
  end
46
44
  @data
@@ -92,6 +90,10 @@ module CDNConnect
92
90
  (status >= 400)
93
91
  end
94
92
 
93
+ def is_client_error()
94
+ (status >= 400 and status < 500)
95
+ end
96
+
95
97
  def is_bad_request()
96
98
  (status == 400)
97
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdnconnect-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bradley