cdnconnect-api 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/cdnconnect_api.rb +75 -38
- data/lib/cdnconnect_api/response.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f95d221d91731fe7d4e5a692ab98022967568902
|
4
|
+
data.tar.gz: 9dda2004ac29c4c96c5c35e1592086b937bf9f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0054b88586c70b771227ba87abaf86f5bd79d7c53b2eed6cdee8d4ca3029dde8322859428b2a83360dcac5b6d342db04ec7613e3421b423866f1ecb93d695070
|
7
|
+
data.tar.gz: fb945dba898215fe1b5ed8738fc92a6c2a3ef1ab5acb6bbb92e23d626df76d9b4a6ed5edd1784c19a6ed64a15fa359d332b7b709ff4d09e5b9149ef31b7bbe02
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# CDN Connect API Ruby Client, v0.
|
1
|
+
# CDN Connect API Ruby Client, v0.4.0
|
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, changing output formats, convert to WebP image format, etc. The CDN Connect API Ruby Client makes it easier to upload files and interact with the API with only a few lines of code.
|
4
4
|
|
data/lib/cdnconnect_api.rb
CHANGED
@@ -25,7 +25,7 @@ module CDNConnect
|
|
25
25
|
class APIClient
|
26
26
|
|
27
27
|
@@application_name = 'cdnconnect-api-ruby'
|
28
|
-
@@application_version = '0.
|
28
|
+
@@application_version = '0.4.0'
|
29
29
|
@@user_agent = @@application_name + ' v' + @@application_version
|
30
30
|
@@api_host = 'https://api.cdnconnect.com'
|
31
31
|
@@api_version = 'v1'
|
@@ -172,7 +172,11 @@ module CDNConnect
|
|
172
172
|
# or `xml`. The defautl format is `json`.
|
173
173
|
#
|
174
174
|
# @return [APIResponse] A response object with helper methods to read the response.
|
175
|
-
def upload(options
|
175
|
+
def upload(options)
|
176
|
+
if options[:app_host] == nil
|
177
|
+
options[:app_host] = @app_host
|
178
|
+
end
|
179
|
+
|
176
180
|
# Make sure we've got good source data before starting the upload
|
177
181
|
prepare_upload(options)
|
178
182
|
|
@@ -200,7 +204,7 @@ module CDNConnect
|
|
200
204
|
# will need to make a request for an upload url. After the first upload
|
201
205
|
# each upload response will also include a new upload url which can be used
|
202
206
|
# for the next upload when uploading to the same folder.
|
203
|
-
upload_url_response = self.get_upload_url(destination_path)
|
207
|
+
upload_url_response = self.get_upload_url(options, destination_path)
|
204
208
|
if upload_url_response.is_error
|
205
209
|
return upload_url_response
|
206
210
|
end
|
@@ -530,7 +534,7 @@ module CDNConnect
|
|
530
534
|
# This method should not be called directly, but is used by the upload method
|
531
535
|
# to get the options all ready to go and validated before uploading a file(s).
|
532
536
|
# @!visibility private
|
533
|
-
def prepare_upload(options
|
537
|
+
def prepare_upload(options)
|
534
538
|
|
535
539
|
# Check if we've got valid source files
|
536
540
|
if options[:source_folder_path] != nil
|
@@ -600,18 +604,18 @@ module CDNConnect
|
|
600
604
|
# upload url is received, all upload responses contain another upload which can be
|
601
605
|
# used to eliminate the need to do seperate requests for an upload url.
|
602
606
|
# @!visibility private
|
603
|
-
def get_upload_url(destination_path)
|
607
|
+
def get_upload_url(options, destination_path)
|
604
608
|
if destination_path == "/"
|
605
609
|
destination_path = ""
|
606
610
|
end
|
607
611
|
upload_id = ((9_999_999 - 1_000_000) * rand + 1_000_000).to_i
|
608
|
-
|
612
|
+
path = "/#{options[:app_host]}#{destination_path}/upload-#{upload_id}.json"
|
609
613
|
|
610
|
-
@logger.debug("get_upload_url: #{
|
614
|
+
@logger.debug("get_upload_url: #{path}")
|
611
615
|
|
612
616
|
i = 1
|
613
617
|
begin
|
614
|
-
response = get(
|
618
|
+
response = get(path)
|
615
619
|
if not response.is_server_error
|
616
620
|
return response
|
617
621
|
elsif i > 2
|
@@ -637,8 +641,11 @@ module CDNConnect
|
|
637
641
|
# True or false value indicating if a folder's response should contain
|
638
642
|
# its sub-folders or not. Default is false.
|
639
643
|
# @return [APIResponse] A response object with helper methods to read the response.
|
640
|
-
def get_object(options
|
641
|
-
|
644
|
+
def get_object(options)
|
645
|
+
if options[:app_host] == nil
|
646
|
+
options[:app_host] = @app_host
|
647
|
+
end
|
648
|
+
path = "/#{options[:app_host]}#{options[:path]}.json"
|
642
649
|
data = {}
|
643
650
|
if options[:files] == true
|
644
651
|
data[:files] = true
|
@@ -646,7 +653,7 @@ module CDNConnect
|
|
646
653
|
if options[:folders] == true
|
647
654
|
data[:folders] = true
|
648
655
|
end
|
649
|
-
get(
|
656
|
+
get(path, data)
|
650
657
|
end
|
651
658
|
|
652
659
|
|
@@ -659,10 +666,13 @@ module CDNConnect
|
|
659
666
|
# - <code>:new_name</code> -
|
660
667
|
# The new filename or folder name for the object. (required)
|
661
668
|
# @return [APIResponse] A response object with helper methods to read the response.
|
662
|
-
def rename_object(options
|
663
|
-
|
669
|
+
def rename_object(options)
|
670
|
+
if options[:app_host] == nil
|
671
|
+
options[:app_host] = @app_host
|
672
|
+
end
|
673
|
+
path = "/#{options[:app_host]}#{options[:path]}/rename.json"
|
664
674
|
data = { :new_name => options[:new_name] }
|
665
|
-
put(
|
675
|
+
put(path, data)
|
666
676
|
end
|
667
677
|
|
668
678
|
|
@@ -673,9 +683,12 @@ module CDNConnect
|
|
673
683
|
# - <code>:path</code> -
|
674
684
|
# The path to the CDN Connect object to delete. (required)
|
675
685
|
# @return [APIResponse] A response object with helper methods to read the response.
|
676
|
-
def delete_object(options
|
677
|
-
|
678
|
-
|
686
|
+
def delete_object(options)
|
687
|
+
if options[:app_host] == nil
|
688
|
+
options[:app_host] = @app_host
|
689
|
+
end
|
690
|
+
path = "/#{options[:app_host]}#{options[:path]}.json"
|
691
|
+
delete(path)
|
679
692
|
end
|
680
693
|
|
681
694
|
|
@@ -684,9 +697,33 @@ module CDNConnect
|
|
684
697
|
# already exist they will be created.
|
685
698
|
#
|
686
699
|
# @return [APIResponse] A response object with helper methods to read the response.
|
687
|
-
def create_path(options
|
688
|
-
|
689
|
-
|
700
|
+
def create_path(options)
|
701
|
+
if options[:app_host] == nil
|
702
|
+
options[:app_host] = @app_host
|
703
|
+
end
|
704
|
+
path = "/#{options[:app_host]}#{options[:path]}/create-path.json"
|
705
|
+
get(path)
|
706
|
+
end
|
707
|
+
|
708
|
+
|
709
|
+
##
|
710
|
+
# Create a new CDN Connect app. The creator of the app will be the
|
711
|
+
# same user as the creator of the API Key for the request.
|
712
|
+
#
|
713
|
+
# @param [Hash] options
|
714
|
+
# The configuration parameters for the client.
|
715
|
+
# - <code>:subdomain</code> -
|
716
|
+
# This new app's subdomain to the "cdnconnect.com" domain.
|
717
|
+
# - <code>:label</code> -
|
718
|
+
# The label for this new app.
|
719
|
+
#
|
720
|
+
# @return [APIResponse] A response object with helper methods to read the response.
|
721
|
+
def create_app(options)
|
722
|
+
path = '/apps.json'
|
723
|
+
data = {}
|
724
|
+
data[:subdomain] = options[:subdomain]
|
725
|
+
data[:label] = options[:label]
|
726
|
+
post(path, data)
|
690
727
|
end
|
691
728
|
|
692
729
|
|
@@ -694,11 +731,11 @@ module CDNConnect
|
|
694
731
|
# Executes a GET request to an API URL and returns a response object.
|
695
732
|
# GET requests are used when reading data.
|
696
733
|
#
|
697
|
-
# @param
|
734
|
+
# @param path [String] The API path to send the GET request to.
|
698
735
|
# @param data [Hash] Data which will be placed in the GET request's querystring. (Optional)
|
699
736
|
# @return [APIResponse] A response object with helper methods to read the response.
|
700
|
-
def get(
|
701
|
-
fetch(:
|
737
|
+
def get(path, data={})
|
738
|
+
fetch(:path => path, :method => 'GET', :data => data)
|
702
739
|
end
|
703
740
|
|
704
741
|
|
@@ -706,11 +743,11 @@ module CDNConnect
|
|
706
743
|
# Executes a POST request to an API URL and returns a response object.
|
707
744
|
# POST requests are used when creating data.
|
708
745
|
#
|
709
|
-
# @param
|
746
|
+
# @param path [String] The API path to send the POST request to.
|
710
747
|
# @param data [Hash] Data which will be sent in the POST request.
|
711
748
|
# @return [APIResponse] A response object with helper methods to read the response.
|
712
|
-
def post(
|
713
|
-
fetch(:
|
749
|
+
def post(path, data)
|
750
|
+
fetch(:path => path, :method => 'POST', :data => data)
|
714
751
|
end
|
715
752
|
|
716
753
|
|
@@ -718,11 +755,11 @@ module CDNConnect
|
|
718
755
|
# Executes a PUT request to an API URL and returns a response object.
|
719
756
|
# PUT requests are used when updating data.
|
720
757
|
#
|
721
|
-
# @param
|
758
|
+
# @param path [String] The API path to send the PUT request to.
|
722
759
|
# @param data [Hash] Data which will be sent in the PUT request.
|
723
760
|
# @return [APIResponse] A response object with helper methods to read the response.
|
724
|
-
def put(
|
725
|
-
fetch(:
|
761
|
+
def put(path, data)
|
762
|
+
fetch(:path => path, :method => 'PUT', :data => data)
|
726
763
|
end
|
727
764
|
|
728
765
|
|
@@ -730,24 +767,24 @@ module CDNConnect
|
|
730
767
|
# Executes a DELETE request to an API URL and returns a response object.
|
731
768
|
# DELETE requests are used when (you guessed it) deleting data.
|
732
769
|
#
|
733
|
-
# @param
|
770
|
+
# @param path [String] The API path to send the DELETE request to.
|
734
771
|
# @return [APIResponse] A response object with helper methods to read the response.
|
735
|
-
def delete(
|
736
|
-
fetch(:
|
772
|
+
def delete(path)
|
773
|
+
fetch(:path => path, :method => 'DELETE')
|
737
774
|
end
|
738
|
-
|
775
|
+
|
739
776
|
|
740
777
|
##
|
741
778
|
# This method should not be called directly, but is used to validate data
|
742
779
|
# and make it all pretty before firing off the request to the API.
|
743
780
|
# @!visibility private
|
744
|
-
def prepare(options
|
745
|
-
if options[:
|
746
|
-
raise ArgumentError, 'missing
|
781
|
+
def prepare(options)
|
782
|
+
if options[:path] == nil
|
783
|
+
raise ArgumentError, 'missing path'
|
747
784
|
end
|
748
785
|
|
749
786
|
options[:headers] = { 'User-Agent' => @@user_agent }
|
750
|
-
options[:uri] = "#{@@api_host}/#{@@api_version}
|
787
|
+
options[:uri] = "#{@@api_host}/#{@@api_version}#{options[:path]}"
|
751
788
|
|
752
789
|
options[:method] = options[:method] || 'GET'
|
753
790
|
|
@@ -768,7 +805,7 @@ module CDNConnect
|
|
768
805
|
##
|
769
806
|
# Guts of an authorized request. Do not call this directly.
|
770
807
|
# @!visibility private
|
771
|
-
def fetch(options
|
808
|
+
def fetch(options)
|
772
809
|
# Prepare the data to be shipped in the request
|
773
810
|
options = prepare(options)
|
774
811
|
|
@@ -30,8 +30,8 @@ module CDNConnect
|
|
30
30
|
@data = nil
|
31
31
|
@body = nil
|
32
32
|
else
|
33
|
-
@status =
|
34
|
-
@data = {"results" => {}, "msgs" => []}
|
33
|
+
@status = 503
|
34
|
+
@data = { "results" => {}, "msgs" => [{"text" => "http_response was nil", "status" => "error"}] }
|
35
35
|
@body = nil
|
36
36
|
end
|
37
37
|
return self
|
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.
|
4
|
+
version: 0.4.0
|
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-09-
|
11
|
+
date: 2013-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|