radiospiel-app 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/config/app.yml +3 -0
- data/lib/extensions/bitly.rb +34 -0
- data/lib/extensions/http.rb +13 -3
- data/radiospiel-app.gemspec +5 -1
- data/test/bitlify_test.rb +28 -0
- data/test/config_test.rb +4 -1
- data/test/fixtures-vcr/bitly_limit_exceeded.yml +43 -0
- data/test/fixtures-vcr/bitly_ok.yml +46 -0
- metadata +30 -26
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/config/app.yml
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "cgi"
|
2
|
+
|
3
|
+
module Bitly
|
4
|
+
TIME_TO_LIVE = 365 * 24 * 3600
|
5
|
+
|
6
|
+
def self.url_base
|
7
|
+
return @url_base unless @url_base.nil?
|
8
|
+
|
9
|
+
user, key = (App.config[:bitly] || {}).values_at "user", "key"
|
10
|
+
|
11
|
+
@url_base = unless user && key
|
12
|
+
App.logger.warn "Missing or invalid bitly configuration: #{App.config[:bitly]}"
|
13
|
+
false
|
14
|
+
else
|
15
|
+
"https://api-ssl.bitly.com/v3/shorten?login=#{user}&apiKey=#{key}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.shorten(url)
|
20
|
+
return url if !self.url_base || !url || url.index("/bit.ly/")
|
21
|
+
|
22
|
+
bitly_url = "#{self.url_base}&longUrl=#{CGI.escape(url)}"
|
23
|
+
parsed = JSON.parse Http.get(bitly_url, TIME_TO_LIVE)
|
24
|
+
|
25
|
+
if parsed["status_code"] == 200
|
26
|
+
bitlified = parsed["data"]["url"]
|
27
|
+
App.logger.debug "bitlify: #{url} => #{bitlified}"
|
28
|
+
bitlified
|
29
|
+
else
|
30
|
+
App.logger.error "#{url}: bitly error: #{parsed["status_txt"] }"
|
31
|
+
url
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/extensions/http.rb
CHANGED
@@ -24,8 +24,10 @@ module Http
|
|
24
24
|
|
25
25
|
def get(url, max_age = MaxAge.for(url))
|
26
26
|
App.logger.benchmark("[GET] #{url}", :minimum => 20) do
|
27
|
-
App.
|
28
|
-
|
27
|
+
App.cached(url, max_age) do
|
28
|
+
App.logger.debug "[GET] #{url}"
|
29
|
+
get_(url)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -34,7 +36,15 @@ module Http
|
|
34
36
|
def get_(uri_str, limit = 10)
|
35
37
|
raise 'too many redirections' if limit == 0
|
36
38
|
|
37
|
-
|
39
|
+
uri = URI.parse(uri_str)
|
40
|
+
|
41
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
42
|
+
if uri.scheme == "https"
|
43
|
+
http.use_ssl = true
|
44
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
45
|
+
end
|
46
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
47
|
+
response = http.request(request)
|
38
48
|
|
39
49
|
case response
|
40
50
|
when Net::HTTPSuccess then
|
data/radiospiel-app.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "radiospiel-app"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["radiospiel"]
|
@@ -42,16 +42,20 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/core-extensions/string_without_accents.rb",
|
43
43
|
"lib/core-extensions/tls.rb",
|
44
44
|
"lib/core-extensions/uids.rb",
|
45
|
+
"lib/extensions/bitly.rb",
|
45
46
|
"lib/extensions/http.rb",
|
46
47
|
"lib/extensions/zz_geocoder.rb",
|
47
48
|
"radiospiel-app.gemspec",
|
48
49
|
"script/watchr",
|
49
50
|
"test/app_test.rb",
|
50
51
|
"test/array_ext_test.rb",
|
52
|
+
"test/bitlify_test.rb",
|
51
53
|
"test/cache_test.rb",
|
52
54
|
"test/cgi_ext_test.rb",
|
53
55
|
"test/config.yml",
|
54
56
|
"test/config_test.rb",
|
57
|
+
"test/fixtures-vcr/bitly_limit_exceeded.yml",
|
58
|
+
"test/fixtures-vcr/bitly_ok.yml",
|
55
59
|
"test/fixtures-vcr/geocoder.yml",
|
56
60
|
"test/fixtures-vcr/http_test.yml",
|
57
61
|
"test/geocoder_test.rb",
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative './helper'
|
4
|
+
require 'vcr'
|
5
|
+
|
6
|
+
VCR.configure do |c|
|
7
|
+
c.cassette_library_dir = "#{File.dirname(__FILE__)}/fixtures-vcr"
|
8
|
+
c.hook_into :webmock
|
9
|
+
end
|
10
|
+
|
11
|
+
class BitlifyTest < Test::Unit::TestCase
|
12
|
+
def test_limit_exceeded
|
13
|
+
VCR.use_cassette('bitly_limit_exceeded') do
|
14
|
+
assert_equal("http://radiospiel.org/foo", Bitly.shorten("http://radiospiel.org/foo"))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ok
|
19
|
+
VCR.use_cassette('bitly_ok') do
|
20
|
+
assert_equal("http://bit.ly/HV7woD", Bitly.shorten("http://radiospiel.org/a=1&b=2"))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_url_base
|
25
|
+
expected = "https://api-ssl.bitly.com/v3/shorten?login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07"
|
26
|
+
assert_equal expected, Bitly.url_base
|
27
|
+
end
|
28
|
+
end
|
data/test/config_test.rb
CHANGED
@@ -5,7 +5,10 @@ class TestConfig < Test::Unit::TestCase
|
|
5
5
|
App.root = File.dirname __FILE__
|
6
6
|
|
7
7
|
expected = {"abc"=>"def", "dummy"=>"dummy", "erbed"=> "test" }
|
8
|
-
|
8
|
+
|
9
|
+
expected.each do |key, expected_value|
|
10
|
+
assert_equal(expected_value, App.config[key])
|
11
|
+
end
|
9
12
|
|
10
13
|
assert_equal("def", App.config[:abc])
|
11
14
|
assert_equal("def", App.config["abc"])
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api-ssl.bitly.com/v3/shorten?apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&login=bitlyapidemo&longUrl=http://radiospiel.org/foo
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- ! '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
!binary "U2VydmVy":
|
20
|
+
- !binary |-
|
21
|
+
bmdpbng=
|
22
|
+
!binary "RGF0ZQ==":
|
23
|
+
- !binary |-
|
24
|
+
V2VkLCAwNCBBcHIgMjAxMiAxNTo0OTo0NiBHTVQ=
|
25
|
+
Content-Type:
|
26
|
+
- !binary |-
|
27
|
+
YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
|
28
|
+
!binary "Q29ubmVjdGlvbg==":
|
29
|
+
- !binary |-
|
30
|
+
a2VlcC1hbGl2ZQ==
|
31
|
+
Mime-Version:
|
32
|
+
- !binary |-
|
33
|
+
MS4w
|
34
|
+
Content-Length:
|
35
|
+
- !binary |-
|
36
|
+
NzI=
|
37
|
+
body:
|
38
|
+
encoding: US-ASCII
|
39
|
+
string: ! '{ "data": [ ], "status_code": 403, "status_txt": "RATE_LIMIT_EXCEEDED"
|
40
|
+
}'
|
41
|
+
http_version:
|
42
|
+
recorded_at: Wed, 04 Apr 2012 15:49:46 GMT
|
43
|
+
recorded_with: VCR 2.0.1
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api-ssl.bitly.com/v3/shorten?apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&login=bitlyapidemo&longUrl=http://radiospiel.org/a=1%26b=2
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- ! '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
!binary "U2VydmVy":
|
20
|
+
- !binary |-
|
21
|
+
bmdpbng=
|
22
|
+
!binary "RGF0ZQ==":
|
23
|
+
- !binary |-
|
24
|
+
V2VkLCAwNCBBcHIgMjAxMiAxNTo0NToyOSBHTVQ=
|
25
|
+
Content-Type:
|
26
|
+
- !binary |-
|
27
|
+
YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
|
28
|
+
!binary "Q29ubmVjdGlvbg==":
|
29
|
+
- !binary |-
|
30
|
+
a2VlcC1hbGl2ZQ==
|
31
|
+
Mime-Version:
|
32
|
+
- !binary |-
|
33
|
+
MS4w
|
34
|
+
Content-Length:
|
35
|
+
- !binary |-
|
36
|
+
MTk1
|
37
|
+
body:
|
38
|
+
encoding: US-ASCII
|
39
|
+
string: ! '{ "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/radiospiel.org\/a=1&b=2",
|
40
|
+
"url": "http:\/\/bit.ly\/HV7woD", "hash": "HV7woD", "global_hash": "HV7woE",
|
41
|
+
"new_hash": 1 } }
|
42
|
+
|
43
|
+
'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Wed, 04 Apr 2012 15:45:29 GMT
|
46
|
+
recorded_with: VCR 2.0.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiospiel-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
16
|
-
requirement: &
|
16
|
+
requirement: &70236453274180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70236453274180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70236453272720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70236453272720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: redis
|
38
|
-
requirement: &
|
38
|
+
requirement: &70236453271700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70236453271700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: micro_sql
|
49
|
-
requirement: &
|
49
|
+
requirement: &70236453269420 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70236453269420
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: htmlentities
|
60
|
-
requirement: &
|
60
|
+
requirement: &70236453264520 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70236453264520
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70236453263340 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70236453263340
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: jeweler
|
82
|
-
requirement: &
|
82
|
+
requirement: &70236453261680 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70236453261680
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: vcr
|
93
|
-
requirement: &
|
93
|
+
requirement: &70236453261020 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70236453261020
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: webmock
|
104
|
-
requirement: &
|
104
|
+
requirement: &70236453260440 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70236453260440
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: psych
|
115
|
-
requirement: &
|
115
|
+
requirement: &70236453237140 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70236453237140
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: simplecov
|
126
|
-
requirement: &
|
126
|
+
requirement: &70236453236540 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70236453236540
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: ruby-debug19
|
137
|
-
requirement: &
|
137
|
+
requirement: &70236453236000 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,7 +142,7 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70236453236000
|
146
146
|
description: Some basics that your application could benefit from.
|
147
147
|
email: eno@open-lab.org
|
148
148
|
executables: []
|
@@ -176,16 +176,20 @@ files:
|
|
176
176
|
- lib/core-extensions/string_without_accents.rb
|
177
177
|
- lib/core-extensions/tls.rb
|
178
178
|
- lib/core-extensions/uids.rb
|
179
|
+
- lib/extensions/bitly.rb
|
179
180
|
- lib/extensions/http.rb
|
180
181
|
- lib/extensions/zz_geocoder.rb
|
181
182
|
- radiospiel-app.gemspec
|
182
183
|
- script/watchr
|
183
184
|
- test/app_test.rb
|
184
185
|
- test/array_ext_test.rb
|
186
|
+
- test/bitlify_test.rb
|
185
187
|
- test/cache_test.rb
|
186
188
|
- test/cgi_ext_test.rb
|
187
189
|
- test/config.yml
|
188
190
|
- test/config_test.rb
|
191
|
+
- test/fixtures-vcr/bitly_limit_exceeded.yml
|
192
|
+
- test/fixtures-vcr/bitly_ok.yml
|
189
193
|
- test/fixtures-vcr/geocoder.yml
|
190
194
|
- test/fixtures-vcr/http_test.yml
|
191
195
|
- test/geocoder_test.rb
|
@@ -210,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
214
|
version: '0'
|
211
215
|
segments:
|
212
216
|
- 0
|
213
|
-
hash: -
|
217
|
+
hash: -2366921286656490123
|
214
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
219
|
none: false
|
216
220
|
requirements:
|