ruby-smugmug 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/lib/smugmug/client.rb +11 -1
- data/lib/smugmug/http.rb +26 -6
- data/lib/smugmug/version.rb +1 -1
- metadata +19 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f18f75f74b04a31f48790624e603d7a1a4c12886
|
4
|
+
data.tar.gz: 11e2d02d25249dd8f78a43f3640112cf2d403209
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b786b040771111e7d030f3bce693009cd1896f2ccfbdf49973d650c392b02d94a68780b9a7e01013e42bb9ef0a855924da8770c1eaefd5e579615ac34f348448
|
7
|
+
data.tar.gz: 81d10bc3985f01ec1d6b854ef10f02dd8d68d76d17d56db669e825c2abb33b10b34a66c656d784364d80bc86a9a73cbd07120a855a5b7e3041175cc21568cf7f
|
data/LICENSE
CHANGED
data/lib/smugmug/client.rb
CHANGED
@@ -63,6 +63,16 @@ module SmugMug
|
|
63
63
|
@http.request(:uploading, args)
|
64
64
|
end
|
65
65
|
|
66
|
+
##
|
67
|
+
# Sign a url with OAuth tokens. Useful when you e.g. want to sign private photo URLs,
|
68
|
+
# because otherwise you cannot access them in a cookie-less environment
|
69
|
+
# @param [String] method HTTP method that the request is sent as
|
70
|
+
# @param [String] uri Full URL of the request
|
71
|
+
# @param [Hash] form_args Args to be passed to the server, optional
|
72
|
+
def sign_request(method, url, form_args = {})
|
73
|
+
@http.sign_request(method, url, form_args)
|
74
|
+
end
|
75
|
+
|
66
76
|
##
|
67
77
|
# Direct mapping of SmugMug 1.3.0 API, either see http://wiki.smugmug.net/display/API/API+1.3.0 or the README for examples
|
68
78
|
#
|
@@ -82,4 +92,4 @@ module SmugMug
|
|
82
92
|
end
|
83
93
|
end
|
84
94
|
end
|
85
|
-
end
|
95
|
+
end
|
data/lib/smugmug/http.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require "cgi"
|
2
1
|
require "openssl"
|
3
2
|
require "base64"
|
4
3
|
require "net/http"
|
@@ -17,7 +16,7 @@ module SmugMug
|
|
17
16
|
#
|
18
17
|
def initialize(args)
|
19
18
|
@config = args
|
20
|
-
@digest = OpenSSL::Digest
|
19
|
+
@digest = OpenSSL::Digest.new("SHA1")
|
21
20
|
|
22
21
|
@headers = {"Accept-Encoding" => "gzip"}
|
23
22
|
if args[:user_agent]
|
@@ -25,13 +24,19 @@ module SmugMug
|
|
25
24
|
else
|
26
25
|
@headers["User-Agent"] = "Ruby-SmugMug v#{SmugMug::VERSION}"
|
27
26
|
end
|
27
|
+
|
28
|
+
args[:http] = args.fetch(:http,{}) #checks for the existance of :http, sets to nill if does not exist.
|
29
|
+
@http_proxy_host = args[:http].fetch(:proxy_host,nil)
|
30
|
+
@http_proxy_port = args[:http].fetch(:proxy_port,nil)
|
31
|
+
@http_proxy_user = args[:http].fetch(:proxy_user,nil)
|
32
|
+
@http_proxy_pass = args[:http].fetch(:proxy_pass,nil)
|
28
33
|
end
|
29
34
|
|
30
35
|
def request(api, args)
|
31
36
|
uri = api == :uploading ? UPLOAD_URI : API_URI
|
32
37
|
args[:method] = "smugmug.#{api}" unless api == :uploading
|
33
38
|
|
34
|
-
http = ::Net::HTTP.new(uri.host, uri.port)
|
39
|
+
http = ::Net::HTTP.new(uri.host, uri.port, @http_proxy_host, @http_proxy_port, @http_proxy_user, @http_proxy_pass)
|
35
40
|
http.set_debug_output(@config[:debug_output]) if @config[:debug_output]
|
36
41
|
|
37
42
|
# Configure HTTPS if needed
|
@@ -135,19 +140,34 @@ module SmugMug
|
|
135
140
|
args["oauth_timestamp"] = Time.now.utc.to_i
|
136
141
|
args["oauth_token"] = @config[:user][:token]
|
137
142
|
|
143
|
+
# RFC 1738 (http://www.ietf.org/rfc/rfc1738.txt) says:
|
144
|
+
#
|
145
|
+
# Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
|
146
|
+
# reserved characters used for their reserved purposes may be used
|
147
|
+
# unencoded within a URL.
|
148
|
+
#
|
149
|
+
# However, if we don't escape apostrophes and parentheses the SmugMug API fails
|
150
|
+
# with an invalid signature error:
|
151
|
+
#
|
152
|
+
# Error #35, invalid signature (SmugMug::OAuthError)
|
153
|
+
#
|
154
|
+
# To overcome this, define a new unreserved character list and use this in URI::escape
|
155
|
+
unreserved = "\\-_.!~*a-zA-Z\\d"
|
156
|
+
unsafe = Regexp.new("[^#{unreserved}]", false, 'N')
|
157
|
+
|
138
158
|
# Sort the params
|
139
159
|
sorted_args = []
|
140
160
|
args.sort.each do |key, value|
|
141
|
-
sorted_args.push("#{key.to_s}=#{
|
161
|
+
sorted_args.push("#{key.to_s}=#{URI::escape(value.to_s, unsafe)}")
|
142
162
|
end
|
143
163
|
|
144
164
|
postdata = sorted_args.join("&")
|
145
165
|
|
146
166
|
# Final string to hash
|
147
|
-
sig_base = "#{method}&#{
|
167
|
+
sig_base = "#{method}&#{URI::escape("#{uri.scheme}://#{uri.host}#{uri.path}", unsafe)}&#{URI::escape(postdata, unsafe)}"
|
148
168
|
|
149
169
|
signature = OpenSSL::HMAC.digest(@digest, "#{@config[:oauth_secret]}&#{@config[:user][:secret]}", sig_base)
|
150
|
-
signature =
|
170
|
+
signature = URI::escape(Base64.encode64(signature).chomp, unsafe)
|
151
171
|
|
152
172
|
if uri == API_URI
|
153
173
|
"#{postdata}&oauth_signature=#{signature}"
|
data/lib/smugmug/version.rb
CHANGED
metadata
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-smugmug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Zachary Anker
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
19
|
+
version: '1.8'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
26
|
+
version: '1.8'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 2.8
|
33
|
+
version: '2.8'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.8
|
40
|
+
version: '2.8'
|
46
41
|
description: Gem for reading and writing data from the SmugMug 1.3.0 API.
|
47
42
|
email:
|
48
43
|
- zach.anker@gmail.com
|
@@ -50,6 +45,9 @@ executables: []
|
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
52
47
|
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
53
51
|
- lib/ruby-smugmug.rb
|
54
52
|
- lib/smugmug/api_category.rb
|
55
53
|
- lib/smugmug/api_methods.rb
|
@@ -57,31 +55,28 @@ files:
|
|
57
55
|
- lib/smugmug/exceptions.rb
|
58
56
|
- lib/smugmug/http.rb
|
59
57
|
- lib/smugmug/version.rb
|
60
|
-
- LICENSE
|
61
|
-
- README.md
|
62
|
-
- Rakefile
|
63
58
|
homepage: http://github.com/zanker/ruby-smugmug
|
64
59
|
licenses: []
|
60
|
+
metadata: {}
|
65
61
|
post_install_message:
|
66
62
|
rdoc_options: []
|
67
63
|
require_paths:
|
68
64
|
- lib
|
69
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
66
|
requirements:
|
72
|
-
- -
|
67
|
+
- - ">="
|
73
68
|
- !ruby/object:Gem::Version
|
74
69
|
version: '0'
|
75
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
71
|
requirements:
|
78
|
-
- -
|
72
|
+
- - ">="
|
79
73
|
- !ruby/object:Gem::Version
|
80
74
|
version: 1.3.6
|
81
75
|
requirements: []
|
82
76
|
rubyforge_project: ruby-smugmug
|
83
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.4.5
|
84
78
|
signing_key:
|
85
|
-
specification_version:
|
79
|
+
specification_version: 4
|
86
80
|
summary: SmugMug 1.3.0 API gem
|
87
81
|
test_files: []
|
82
|
+
has_rdoc:
|