flickraw 0.9.8 → 0.9.9

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: bc6ebd96bb86d75cb32adff22f3e2110405c9d53
4
- data.tar.gz: c00d50468c5b8aa775bd0a9145d590c83fc4365a
3
+ metadata.gz: cdf1d2ebe95cae5115bb7e53b0e4e8f4dc9fa56a
4
+ data.tar.gz: 0e68d6ee1844edab7fb300051993cf071711e036
5
5
  SHA512:
6
- metadata.gz: 6e600b2afe460bc96a670a0a20d7a1815cca53af6091191884f65177a843ee2d534f7a5eb1bbe965579643411f3f27dcbed1e8d26f3b4075011006d9c8b882bf
7
- data.tar.gz: e784c567318a3483d5ae9c31f17aa5ca5fb8433caae3361f9c5bcd7e74664821bc5e99a2156e045eba809baeb6d5a9403078395398630b56636bd9caf36c075c
6
+ metadata.gz: 3d28e97c5452a9a8f662b565b02c24100bf91462b77db11a179e638ec51425efaad66a9d203b6fad997cdaac9b25c9935cb6145cb8230e62d7c16a7f16361881
7
+ data.tar.gz: eea3e153758348555ca757fd996089b3dad4bfda8b43eb774f2c052ef4d8f1c46411107d8ee2e87a09a9a8a245839153033a8a7749a2521fc26d2868357013d8
@@ -101,7 +101,7 @@ If you need to have several users authenticated at the same time in your applica
101
101
 
102
102
  PHOTO_PATH='photo.jpg'
103
103
 
104
- # You need to be authentified to do that, see the previous examples.
104
+ # You need to be authenticated to do that, see the previous examples.
105
105
  flickr.upload_photo PHOTO_PATH, :title => "Title", :description => "This is the description"
106
106
 
107
107
  == Proxy
@@ -116,11 +116,40 @@ https endpoints are used by default. If you want to use unencrypted endpoints :
116
116
  require 'flickraw'
117
117
  FlickRaw.secure = false
118
118
 
119
+ === Server Certificate Verification
120
+
121
+ Server certificate verification is enabled by default. If you don't want to check the server certificate :
122
+
123
+ require 'flickraw'
124
+ FlickRaw.check_certificate = false
125
+
126
+ === CA Certificate File Path
127
+
128
+ OpenSSL::X509::DEFAULT_CERT_FILE is used as a CA certificate file. If you want to change the path :
129
+
130
+ require 'flickraw'
131
+ FlickRaw.ca_file = '/path/to/cacert.pem'
132
+
133
+ You can also specify a path to a directory with a number of certifications:
134
+
135
+ FlickRaw.ca_path = '/path/to/certificates'
136
+
119
137
  == Flickr URL Helpers
120
138
 
121
139
  There are some helpers to build flickr urls :
122
140
 
123
141
  === url, url_m, url_s, url_t, url_b, url_z, url_q, url_n, url_c, url_o
142
+
143
+ # url_s : Square
144
+ # url_q : Large Square
145
+ # url_t : Thumbnail
146
+ # url_m : Small
147
+ # url_n : Small 320
148
+ # url : Medium
149
+ # url_z : Medium 640
150
+ # url_c : Medium 800
151
+ # url_b : Large
152
+ # url_o : Original
124
153
 
125
154
  info = flickr.photos.getInfo(:photo_id => "3839885270")
126
155
  FlickRaw.url_b(info) # => "https://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_b.jpg"
@@ -3,7 +3,7 @@ require 'sinatra'
3
3
 
4
4
  FlickRaw.api_key = API_KEY
5
5
  FlickRaw.shared_secret = SHARED_SECRET
6
- enable :sessions
6
+ use Rack::Session::Pool
7
7
 
8
8
  get '/authenticate' do
9
9
  token = flickr.get_request_token(:oauth_callback => to('check'))
@@ -15,17 +15,17 @@ get '/check' do
15
15
  token = session.delete :token
16
16
  session[:auth_flickr] = @auth_flickr = FlickRaw::Flickr.new
17
17
  @auth_flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], params['oauth_verifier'])
18
-
18
+
19
19
  redirect to('/authenticated')
20
20
  end
21
21
 
22
22
  get '/authenticated' do
23
23
  @auth_flickr = session[:auth_flickr]
24
-
24
+
25
25
  login = @auth_flickr.test.login
26
26
  %{
27
27
  You are now authenticated as <em>#{login.username}</em>
28
28
  with token <strong>#{@auth_flickr.access_token}</strong> and secret <strong>#{@auth_flickr.access_secret}</strong>.
29
- }
29
+ }
30
30
  end
31
31
 
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'flickraw/util'
2
3
  require 'flickraw/error'
3
4
  require 'flickraw/oauth'
4
5
  require 'flickraw/request'
@@ -6,10 +7,11 @@ require 'flickraw/response'
6
7
  require 'flickraw/api'
7
8
 
8
9
  module FlickRaw
9
- VERSION='0.9.8'
10
+ VERSION='0.9.9'
10
11
  USER_AGENT = "FlickRaw/#{VERSION}"
11
12
 
12
13
  self.secure = true
14
+ self.check_certificate = true
13
15
  end
14
16
 
15
17
  # Use this to access the flickr API easily. You can type directly the flickr requests as they are described on the flickr website.
@@ -36,12 +36,19 @@ module FlickRaw
36
36
 
37
37
  def self.build(methods); methods.each { |m| build_request m } end
38
38
 
39
- def initialize # :nodoc:
40
- if FlickRaw.api_key.nil? or FlickRaw.shared_secret.nil?
41
- raise FlickrAppNotConfigured.new("No API key or secret defined!")
39
+ def initialize(api_key: FlickRaw.api_key,
40
+ shared_secret: FlickRaw.shared_secret)
41
+ if api_key.nil?
42
+ raise FlickrAppNotConfigured.new("No API key defined!")
42
43
  end
43
- @oauth_consumer = OAuthClient.new(FlickRaw.api_key, FlickRaw.shared_secret)
44
+ if shared_secret.nil?
45
+ raise FlickrAppNotConfigured.new("No shared secret defined!")
46
+ end
47
+ @oauth_consumer = OAuthClient.new(api_key, shared_secret)
44
48
  @oauth_consumer.proxy = FlickRaw.proxy
49
+ @oauth_consumer.check_certificate = FlickRaw.check_certificate
50
+ @oauth_consumer.ca_file = FlickRaw.ca_file
51
+ @oauth_consumer.ca_path = FlickRaw.ca_path
45
52
  @oauth_consumer.user_agent = USER_AGENT
46
53
  @access_token = @access_secret = nil
47
54
 
@@ -164,7 +171,16 @@ module FlickRaw
164
171
 
165
172
  # Use ssl connection
166
173
  attr_accessor :secure
174
+
175
+ # Check the server certificate (ssl connection only)
176
+ attr_accessor :check_certificate
167
177
 
178
+ # Set path of a CA certificate file in PEM format (ssl connection only)
179
+ attr_accessor :ca_file
180
+
181
+ # Set path to a directory of CA certificate files in PEM format (ssl connection only)
182
+ attr_accessor :ca_path
183
+
168
184
  BASE58_ALPHABET="123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ".freeze
169
185
  def base58(id)
170
186
  id = id.to_i
@@ -63,6 +63,9 @@ module FlickRaw
63
63
 
64
64
  attr_accessor :user_agent
65
65
  attr_reader :proxy
66
+ attr_accessor :check_certificate
67
+ attr_accessor :ca_file
68
+ attr_accessor :ca_path
66
69
  def proxy=(url); @proxy = URI.parse(url || '') end
67
70
 
68
71
  def initialize(consumer_key, consumer_secret)
@@ -144,6 +147,9 @@ module FlickRaw
144
147
 
145
148
  http = Net::HTTP.new(url.host, url.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)
146
149
  http.use_ssl = (url.scheme == 'https')
150
+ http.verify_mode = (@check_certificate ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE)
151
+ http.ca_file = @ca_file
152
+ http.ca_path = @ca_path
147
153
  r = http.start {|agent|
148
154
  request = Net::HTTP::Post.new(url.path)
149
155
  request['User-Agent'] = @user_agent if @user_agent
@@ -32,7 +32,7 @@ class Request
32
32
  def #{req}(*args, &block)
33
33
  @flickr.call("#{request_name}.#{req}", *args, &block)
34
34
  end
35
- }
35
+ } if Util.safe_for_eval?(req)
36
36
  flickr_methods << req
37
37
  end
38
38
  end
@@ -22,7 +22,7 @@ class Response
22
22
  when Array then v.collect {|e| Response.build(e, k)}
23
23
  else v
24
24
  end
25
- methods << "def #{k}; @h['#{k}'] end;"
25
+ methods << "def #{k}; @h['#{k}'] end;" if Util.safe_for_eval?(k)
26
26
  }
27
27
  eval methods << "end"
28
28
  end
@@ -0,0 +1,14 @@
1
+ module FlickRaw
2
+ module Util
3
+ extend self
4
+
5
+ def sanitize(string)
6
+ string.gsub(/\W+/, '_') if string
7
+ end
8
+
9
+ def safe_for_eval?(string)
10
+ string == sanitize(string)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ lib = File.dirname(__FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ require 'test/unit'
7
+ require 'helper'
8
+
9
+ class TestReqeust < Test::Unit::TestCase
10
+
11
+ def test_flickr_api_is_accessible_via_methods
12
+ # Reset FlickRaw (was initialized in test/helper.rb) so the request methods
13
+ # are properly built
14
+ $flickraw = nil
15
+ FlickRaw::Request.instance_variable_set(:@flickr_objects, nil)
16
+
17
+ FlickRaw::Flickr.build(['flickr.fully.legal'])
18
+
19
+ assert_equal true, flickr.methods.include?(:fully)
20
+ assert_equal true, flickr.fully.methods.include?(:legal)
21
+ end
22
+
23
+ def test_invalid_keys_are_skipped
24
+ assert_nothing_raised {
25
+ FlickRaw::Flickr.build ["flickr.hacked; end; raise 'Pwned'; def x"]
26
+ }
27
+
28
+ assert_equal false, flickr.methods.include?(:hacked)
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ lib = File.dirname(__FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ require 'test/unit'
7
+ require 'helper'
8
+
9
+ class TestResponse < Test::Unit::TestCase
10
+
11
+ def test_response_keys_are_turned_into_methods
12
+ subject = FlickRaw::Response.new({ 'le_gal' => 'ok', }, nil)
13
+
14
+ assert_equal true, subject.methods.include?(:le_gal)
15
+ assert_equal 'ok', subject.le_gal
16
+ end
17
+
18
+ def test_invalid_keys_are_skipped
19
+ response_hash = {
20
+ 'illegal; end; raise "Pwned"; def x' => 'skipped'
21
+ }
22
+
23
+ assert_nothing_raised {
24
+ FlickRaw::Response.new(response_hash, nil)
25
+ }
26
+
27
+ subject = FlickRaw::Response.new(response_hash, nil)
28
+ assert_equal false, subject.methods.include?(:illegal)
29
+ end
30
+
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickraw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mael Clerambault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-06 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: mael@clerambault.fr
@@ -16,25 +16,28 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - LICENSE
20
- - README.rdoc
21
19
  - examples/auth.rb
22
20
  - examples/interestingness.rb
23
21
  - examples/search.rb
24
22
  - examples/sinatra.rb
25
23
  - examples/upload.rb
26
24
  - examples/web_oauth.rb
27
- - flickraw_rdoc.rb
28
- - lib/flickraw.rb
25
+ - test/helper.rb
26
+ - test/test.rb
27
+ - test/test_request.rb
28
+ - test/test_response.rb
29
+ - test/test_upload.rb
29
30
  - lib/flickraw/api.rb
30
31
  - lib/flickraw/error.rb
31
32
  - lib/flickraw/oauth.rb
32
33
  - lib/flickraw/request.rb
33
34
  - lib/flickraw/response.rb
35
+ - lib/flickraw/util.rb
36
+ - lib/flickraw.rb
37
+ - flickraw_rdoc.rb
38
+ - LICENSE
39
+ - README.rdoc
34
40
  - rakefile
35
- - test/helper.rb
36
- - test/test.rb
37
- - test/test_upload.rb
38
41
  homepage: http://hanklords.github.com/flickraw/
39
42
  licenses:
40
43
  - MIT
@@ -55,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
58
  version: '0'
56
59
  requirements: []
57
60
  rubyforge_project:
58
- rubygems_version: 2.2.2
61
+ rubygems_version: 2.0.14
59
62
  signing_key:
60
63
  specification_version: 4
61
64
  summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api