rest-more 3.0.0 → 3.1.0

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: 114edfb70e3422213e0ce427a3485d50286fc3ef
4
- data.tar.gz: 696bac783f1f2d55260ace0410bd1df717ca5ea5
3
+ metadata.gz: 2e31b7b448ea1e4dce6284fb2a7ecbacb506d759
4
+ data.tar.gz: 212fdd5674abee559e5c29e55dd4f696dc71c2f0
5
5
  SHA512:
6
- metadata.gz: a5209ab15d420ef791699570c7c27ddb156ce6f989d81d523f52ce452e40f4c1abadfff844ef5e35eef91e48a68aeb869a23f2bcc52323bb5fe8f53c6869fecc
7
- data.tar.gz: 319216fafc3c9fc4205d9edcc70a4a31f0f6776b6a67cfdd79d9b845a3953eedc13f1657d9853e60d498027ee8d3caf6b9670571f30314e310828451e1cd7a58
6
+ metadata.gz: 02fb9f18f3d7a0ce0eac2d2030ceb2a21b9f45b50a13816ce35ec3227d38fae60041f12a577de54ac7035698361ea10997f362eca66cbbfbe5b26f63b10c009f
7
+ data.tar.gz: d80cb820e5c77553e2a61ea6b61a05d56c2fe0552ba7a3af81af5a828897b3f97e2b0d7f3cec60669f25144a16db052f1b3dad79f36557e40a05c751455b7290
data/.travis.yml CHANGED
@@ -9,5 +9,5 @@ rvm:
9
9
  - 1.9.3
10
10
  - 2.0.0
11
11
  - ruby
12
- - rbx
12
+ - rbx-2
13
13
  - jruby
data/CHANGES.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # CHANGES
2
2
 
3
+ ## rest-more 3.1.0 -- 2014-05-09
4
+
5
+ ### Changes for RC::Firebase
6
+
7
+ * Now it would properly follow redirect.
8
+ * Now it would raise an error if we're not giving a secret to RC::Firebase.
9
+ * Now we have RC::Firebase::Error and its subclasses.
10
+ * Introduced RC::Firebase::EventSource which would parse the data instead of
11
+ simply giving the string for onmessage callback.
12
+
13
+ ## rest-more 3.0.0 -- 2014-05-04
14
+
15
+ * Adopted latest rest-core
16
+ * Added `RC::Instagram`, thanks @khoan
17
+ * Added `RC::Firebase`
18
+
3
19
  ## rest-more 2.0.4 -- 2013-04-13
4
20
 
5
21
  * [Facebook::RailsUtil] Since now that we cannot retrieve the access token
data/README.md CHANGED
@@ -141,26 +141,44 @@ for a complete reference, and [RC::Firebase][] for built-in APIs.
141
141
  ``` ruby
142
142
  require 'rest-more'
143
143
 
144
- f = RC::Firebase.new :site => 'https://example.firebaseio.com/',
144
+ f = RC::Firebase.new :site => 'https://SampleChat.firebaseIO-demo.com/',
145
145
  :secret => 'secret',
146
146
  :d => {:auth_data => 'something'},
147
- :log_method => method(:puts)
147
+ :log_method => method(:puts),
148
+ :auth => false # Ignore auth for this example!
149
+
150
+ @reconnect = true
148
151
 
149
- # Listen on test.json
150
- es = f.event_source('test')
151
- es.onopen{ |sock| p sock }
152
- es.onmessage{ |event| p event }
153
- es.onerror{ |error| p error }
152
+ # Streaming over 'users/tom'
153
+ es = f.event_source('users/tom')
154
+ es.onopen { |sock| p sock } # Called when connected
155
+ es.onmessage{ |event, data, sock| p event, data } # Called for each message
156
+ es.onerror { |error, sock| p error } # Called whenever there's an error
157
+ # Extra: If we return true in onreconnect callback, it would automatically
158
+ # reconnect the node for us if disconnected.
159
+ es.onreconnect{ |error, sock| p error; @reconnect }
160
+
161
+ # Start making the request
154
162
  es.start
155
163
 
156
- # Update test.json
157
- p f.put('test', :some => 'data')
158
- p f.post('test', :some => 'other')
159
- p f.get('test')
160
- p f.delete('test')
164
+ # Try to close the connection and see it reconnects automatically
165
+ es.close
161
166
 
162
- # Stop listening on test.json
167
+ # Update users/tom.json
168
+ p f.put('users/tom', :some => 'data')
169
+ p f.post('users/tom', :some => 'other')
170
+ p f.get('users/tom')
171
+ p f.delete('users/tom')
172
+
173
+ # Need to tell onreconnect stops reconnecting, or even if we close
174
+ # the connection manually, it would still try to reconnect again.
175
+ @reconnect = false
176
+
177
+ # Close the connection to gracefully shut it down.
163
178
  es.close
179
+
180
+ # Refresh the auth by resetting it
181
+ f.auth = nil
164
182
  ```
165
183
 
166
184
  ### Github example:
@@ -1,7 +1,7 @@
1
1
 
2
2
  source 'https://rubygems.org/'
3
3
 
4
- gem 'rails', '3.2.16'
4
+ gem 'rails', '~> 3.2.16'
5
5
 
6
6
  gem 'rest-core', :path => '../../rest-core'
7
7
  gem 'rest-more', :path => '../../'
@@ -4,6 +4,12 @@ development: &default
4
4
  app_id: '123'
5
5
  secret: '456'
6
6
  canvas: 'can'
7
+ macebook:
8
+ app_id: 41829
9
+ secret: <%= 'r41829'.reverse %>
10
+ json_response: false
11
+ lang: zh-tw
12
+ auto_authorize_scope: 'publish_stream'
7
13
 
8
14
  production:
9
15
  *default
@@ -41,4 +41,14 @@ class RailsUtilTest < ActiveSupport::TestCase
41
41
  assert_equal('http://test.com/',
42
42
  @controller.send(:rc_facebook_normalized_request_uri))
43
43
  end
44
+
45
+ def test_config
46
+ klass = RC::Builder.client
47
+ RC::RailsUtilUtil.load_config(klass, 'macebook')
48
+
49
+ assert_equal 41829 , klass.default_app_id
50
+ assert_equal 'r41829'.reverse, klass.default_secret
51
+ assert_equal false , klass.default_json_response
52
+ assert_equal 'zh-tw' , klass.default_lang
53
+ end
44
54
  end
@@ -46,7 +46,7 @@ class RestCore::Dropbox::Error < RestCore::Error
46
46
 
47
47
  def self.call env
48
48
  error, code, url = env[RESPONSE_BODY], env[RESPONSE_STATUS],
49
- Middleware.request_uri(env)
49
+ env[REQUEST_URI]
50
50
  return new(error, code, url) unless error.kind_of?(Hash)
51
51
  case code
52
52
  when 400; BadRequest
@@ -40,7 +40,7 @@ class RestCore::Facebook::Error < RestCore::Error
40
40
  end
41
41
 
42
42
  def self.call env
43
- error, url = env[RESPONSE_BODY], Middleware.request_uri(env)
43
+ error, url = env[RESPONSE_BODY], env[REQUEST_URI]
44
44
  return new(error, url) unless error.kind_of?(Hash)
45
45
  if invalid_token?(error)
46
46
  InvalidAccessToken.new(error, url)
@@ -11,20 +11,80 @@ module RestCore
11
11
  use DefaultHeaders, {'Accept' => 'application/json'}
12
12
  use DefaultQuery , nil
13
13
 
14
+ use FollowRedirect, 1
14
15
  use CommonLogger , nil
15
16
  use Cache , nil, 600 do
16
- use ErrorHandler, lambda{ |env|
17
- RuntimeError.new(env[RESPONSE_BODY]['message'])}
17
+ use ErrorHandler, lambda{ |env| Firebase::Error.call(env) }
18
18
  use ErrorDetectorHttp
19
19
  use JsonResponse, true
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
+ class RestCore::Firebase::Error < RestCore::Error
25
+ include RestCore
26
+ class ServerError < Firebase::Error; end
27
+ class ClientError < RestCore::Error; end
28
+
29
+ class BadRequest < Firebase::Error; end
30
+ class Unauthorized < Firebase::Error; end
31
+ class Forbidden < Firebase::Error; end
32
+ class NotFound < Firebase::Error; end
33
+ class NotAcceptable < Firebase::Error; end
34
+ class ExpectationFailed < Firebase::Error; end
35
+
36
+ class InternalServerError < Firebase::Error::ServerError; end
37
+ class BadGateway < Firebase::Error::ServerError; end
38
+ class ServiceUnavailable < Firebase::Error::ServerError; end
39
+
40
+ attr_reader :error, :code, :url
41
+ def initialize error, code, url=''
42
+ @error, @code, @url = error, code, url
43
+ super("[#{code}] #{error.inspect} from #{url}")
44
+ end
45
+
46
+ def self.call env
47
+ error, code, url = env[RESPONSE_BODY], env[RESPONSE_STATUS],
48
+ env[REQUEST_URI]
49
+ return new(error, code, url) unless error.kind_of?(Hash)
50
+ case code
51
+ when 400; BadRequest
52
+ when 401; Unauthorized
53
+ when 403; Forbidden
54
+ when 404; NotFound
55
+ when 406; NotAcceptable
56
+ when 417; ExpectationFailed
57
+ when 500; InternalServerError
58
+ when 502; BadGateway
59
+ when 503; ServiceUnavailable
60
+ else ; self
61
+ end.new(error, code, url)
62
+ end
63
+ end
64
+
24
65
  module RestCore::Firebase::Client
25
66
  include RestCore
26
67
 
68
+ class EventSource < RestCore::EventSource
69
+ def onmessage event=nil, data=nil, sock=nil
70
+ if event
71
+ super(event, Json.decode(data), sock)
72
+ else
73
+ super
74
+ end
75
+ end
76
+ end
77
+
78
+ def request env, app=app
79
+ super(env.merge(REQUEST_PATH => "#{env[REQUEST_PATH]}.json",
80
+ REQUEST_PAYLOAD => Json.encode(env[REQUEST_PAYLOAD])),
81
+ app)
82
+ end
83
+
27
84
  def generate_auth opts={}
85
+ raise Firebase::Error::ClientError.new(
86
+ "Please set your secret") unless secret
87
+
28
88
  header = {:typ => 'JWT', :alg => 'HS256'}
29
89
  claims = {:v => 0, :iat => Time.now.to_i, :d => d}.merge(opts)
30
90
  # http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-26
@@ -33,12 +93,6 @@ module RestCore::Firebase::Client
33
93
  "#{input}.#{base64url(Hmac.sha256(secret, input))}"
34
94
  end
35
95
 
36
- def request env, key=RESPONSE_BODY, app=app
37
- super(env.merge(REQUEST_PATH => "#{env[REQUEST_PATH]}.json",
38
- REQUEST_PAYLOAD => Json.encode(env[REQUEST_PAYLOAD])),
39
- key, app)
40
- end
41
-
42
96
  private
43
97
  def base64url str; [str].pack('m').tr('+/', '-_'); end
44
98
  def default_query; {:auth => auth}; end
@@ -47,4 +101,5 @@ end
47
101
 
48
102
  class RestCore::Firebase
49
103
  include RestCore::Firebase::Client
104
+ self.event_source_class = EventSource
50
105
  end
@@ -45,7 +45,7 @@ class RestCore::Twitter::Error < RestCore::Error
45
45
 
46
46
  def self.call env
47
47
  error, code, url = env[RESPONSE_BODY], env[RESPONSE_STATUS],
48
- Middleware.request_uri(env)
48
+ env[REQUEST_URI]
49
49
  return new(error, code, url) unless error.kind_of?(Hash)
50
50
  case code
51
51
  when 400; BadRequest
@@ -1,6 +1,17 @@
1
1
 
2
2
  module RestCore; end
3
3
  module RestCore::RailsUtilUtil
4
+ def self.load_config klass, namespace=nil, app=Rails
5
+ # make sure the default is there even if there's no config file
6
+ RestCore::Config.default_attributes_module(klass)
7
+
8
+ root = File.expand_path(app.root)
9
+ path = ["#{root}/config/rest-core.yaml", # YAML should use .yaml
10
+ "#{root}/config/rest-core.yml" ].find{|p| File.exist?(p)}
11
+ return if path.nil?
12
+ RestCore::Config.load(klass, path, app.env, namespace)
13
+ end
14
+
4
15
  module Cache
5
16
  def [] key ; read(key) ; end
6
17
  def []= key, value; write(key, value) ; end
@@ -56,7 +67,7 @@ module RestCore::RailsUtilUtil
56
67
  end
57
68
  mod.module_eval(<<-RUBY, __FILE__, __LINE__)
58
69
  def init app=Rails
59
- RestCore::Config.load_for_rails(RestCore::#{name}, '#{meth}', app)
70
+ RestCore::RailsUtilUtil.load_config(RestCore::#{name}, '#{meth}', app)
60
71
  end
61
72
 
62
73
  def included controller
data/lib/rest-more.rb CHANGED
@@ -2,8 +2,6 @@
2
2
  require 'rest-core'
3
3
 
4
4
  module RestCore
5
- autoload :Config , 'rest-core/util/config'
6
-
7
5
  autoload :Dropbox , 'rest-core/client/dropbox'
8
6
  autoload :Facebook , 'rest-core/client/facebook'
9
7
  autoload :Firebase , 'rest-core/client/firebase'
@@ -1,4 +1,4 @@
1
1
 
2
2
  module RestMore
3
- VERSION = '3.0.0'
3
+ VERSION = '3.1.0'
4
4
  end
data/rest-more.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rest-more 3.0.0 ruby lib
2
+ # stub: rest-more 3.1.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rest-more"
6
- s.version = "3.0.0"
6
+ s.version = "3.1.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Lin Jen-Shin (godfat)"]
11
- s.date = "2014-05-04"
11
+ s.date = "2014-05-09"
12
12
  s.description = "Various REST clients such as Facebook and Twitter built with [rest-core][].\n\n[rest-core]: https://github.com/godfat/rest-core"
13
13
  s.email = ["godfat (XD) godfat.org"]
14
14
  s.executables = ["rib-rest-core"]
@@ -57,7 +57,6 @@ Gem::Specification.new do |s|
57
57
  "lib/rest-core/client/linkedin/rails_util.rb",
58
58
  "lib/rest-core/client/twitter.rb",
59
59
  "lib/rest-core/client/twitter/rails_util.rb",
60
- "lib/rest-core/util/config.rb",
61
60
  "lib/rest-core/util/rails_util_util.rb",
62
61
  "lib/rest-more.rb",
63
62
  "lib/rest-more/test.rb",
@@ -66,13 +65,11 @@ Gem::Specification.new do |s|
66
65
  "rest-more.gemspec",
67
66
  "task/README.md",
68
67
  "task/gemgem.rb",
69
- "test/dropbox/test_api.rb",
70
- "test/facebook/config/rest-core.yaml",
68
+ "test/dropbox/test_dropbox.rb",
71
69
  "test/facebook/test_api.rb",
72
70
  "test/facebook/test_default.rb",
73
71
  "test/facebook/test_error.rb",
74
72
  "test/facebook/test_handler.rb",
75
- "test/facebook/test_load_config.rb",
76
73
  "test/facebook/test_misc.rb",
77
74
  "test/facebook/test_oauth.rb",
78
75
  "test/facebook/test_old.rb",
@@ -80,19 +77,19 @@ Gem::Specification.new do |s|
80
77
  "test/facebook/test_parse.rb",
81
78
  "test/facebook/test_serialize.rb",
82
79
  "test/facebook/test_timeout.rb",
83
- "test/instagram/test_api.rb",
84
- "test/twitter/test_api.rb"]
80
+ "test/firebase/test_firebase.rb",
81
+ "test/instagram/test_instagram.rb",
82
+ "test/twitter/test_twitter.rb"]
85
83
  s.homepage = "https://github.com/godfat/rest-more"
86
84
  s.licenses = ["Apache License 2.0"]
87
85
  s.rubygems_version = "2.2.2"
88
86
  s.summary = "Various REST clients such as Facebook and Twitter built with [rest-core][]."
89
87
  s.test_files = [
90
- "test/dropbox/test_api.rb",
88
+ "test/dropbox/test_dropbox.rb",
91
89
  "test/facebook/test_api.rb",
92
90
  "test/facebook/test_default.rb",
93
91
  "test/facebook/test_error.rb",
94
92
  "test/facebook/test_handler.rb",
95
- "test/facebook/test_load_config.rb",
96
93
  "test/facebook/test_misc.rb",
97
94
  "test/facebook/test_oauth.rb",
98
95
  "test/facebook/test_old.rb",
@@ -100,8 +97,9 @@ Gem::Specification.new do |s|
100
97
  "test/facebook/test_parse.rb",
101
98
  "test/facebook/test_serialize.rb",
102
99
  "test/facebook/test_timeout.rb",
103
- "test/instagram/test_api.rb",
104
- "test/twitter/test_api.rb"]
100
+ "test/firebase/test_firebase.rb",
101
+ "test/instagram/test_instagram.rb",
102
+ "test/twitter/test_twitter.rb"]
105
103
 
106
104
  if s.respond_to? :specification_version then
107
105
  s.specification_version = 4
@@ -26,12 +26,8 @@ describe RC::Dropbox do
26
26
  end
27
27
 
28
28
  should 'raise exception when encountering error' do
29
- [401, 402, 403].each{ |status|
30
- check(status, RC::Dropbox::Error)
31
- }
32
-
33
- [500, 502, 503].each{ |status|
34
- check(status, RC::Dropbox::Error::ServerError)
35
- }
29
+ [401, 402, 403].each{ |status| check(status, RC::Dropbox::Error) }
30
+ [500, 502, 503].each{ |status| check(status, RC::Dropbox::Error::
31
+ ServerError) }
36
32
  end
37
33
  end
@@ -0,0 +1,72 @@
1
+
2
+ require 'rest-more/test'
3
+
4
+ describe RC::Firebase do
5
+ before do
6
+ stub(Time).now{ Time.at(0) }
7
+ end
8
+
9
+ after do
10
+ WebMock.reset!
11
+ Muack.verify
12
+ end
13
+
14
+ path = 'https://a.json?auth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9%0A.eyJ2IjowLCJpYXQiOjAsImQiOm51bGx9%0A.C9JtzZhiCrsClNdAQcE7Irngr2BZJCH4x1p-IHxfrAo%3D%0A'
15
+
16
+ def firebase
17
+ RC::Firebase.new(:secret => 'nnf')
18
+ end
19
+
20
+ should 'get true' do
21
+ stub_request(:get, path).to_return(:body => 'true')
22
+ firebase.get('https://a').should.eq true
23
+ end
24
+
25
+ should 'put {"status":"ok"}' do
26
+ json = '{"status":"ok"}'
27
+ rbon = {'status' => 'ok'}
28
+ stub_request(:put, path).with(:body => json).to_return(:body => json)
29
+ firebase.put('https://a', rbon).should.eq rbon
30
+ end
31
+
32
+ should 'parse event source' do
33
+ stub_request(:get, path).to_return(:body => <<-SSE)
34
+ event: put
35
+ data: {}
36
+
37
+ event: keep-alive
38
+ data: null
39
+
40
+ event: invalid
41
+ data: invalid
42
+ SSE
43
+ m = [{'event' => 'put' , 'data' => {}},
44
+ {'event' => 'keep-alive', 'data' => nil}]
45
+ es = firebase.event_source('https://a')
46
+ es.should.kind_of RC::Firebase::Client::EventSource
47
+ es.onmessage do |event, data|
48
+ {'event' => event, 'data' => data}.should.eq m.shift
49
+ end.onerror do |error|
50
+ error.should.kind_of RC::Json::ParseError
51
+ end.start.wait
52
+ m.should.empty
53
+ end
54
+
55
+ check = lambda do |status, klass|
56
+ stub_request(:delete, path).to_return(
57
+ :body => '{}', :status => status)
58
+
59
+ lambda{ firebase.delete('https://a').tap{} }.should.raise(klass)
60
+
61
+ WebMock.reset!
62
+ end
63
+
64
+ should 'raise exception when encountering error' do
65
+ [400, 401, 402, 403, 404, 406, 417].each do |status|
66
+ check[status, RC::Firebase::Error]
67
+ end
68
+ [500, 502, 503].each do |status|
69
+ check[status, RC::Firebase::Error::ServerError]
70
+ end
71
+ end
72
+ end
File without changes
@@ -27,12 +27,8 @@ describe RC::Twitter do
27
27
  end
28
28
 
29
29
  should 'raise exception when encountering error' do
30
- [401, 402, 403].each{ |status|
31
- check(status, RestCore::Twitter::Error)
32
- }
33
-
34
- [500, 502, 503].each{ |status|
35
- check(status, RestCore::Twitter::Error::ServerError)
36
- }
30
+ [401, 402, 403].each{ |status| check(status, RestCore::Twitter::Error) }
31
+ [500, 502, 503].each{ |status| check(status, RestCore::Twitter::Error::
32
+ ServerError) }
37
33
  end
38
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-more
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-04 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-core
@@ -79,7 +79,6 @@ files:
79
79
  - lib/rest-core/client/linkedin/rails_util.rb
80
80
  - lib/rest-core/client/twitter.rb
81
81
  - lib/rest-core/client/twitter/rails_util.rb
82
- - lib/rest-core/util/config.rb
83
82
  - lib/rest-core/util/rails_util_util.rb
84
83
  - lib/rest-more.rb
85
84
  - lib/rest-more/test.rb
@@ -88,13 +87,11 @@ files:
88
87
  - rest-more.gemspec
89
88
  - task/README.md
90
89
  - task/gemgem.rb
91
- - test/dropbox/test_api.rb
92
- - test/facebook/config/rest-core.yaml
90
+ - test/dropbox/test_dropbox.rb
93
91
  - test/facebook/test_api.rb
94
92
  - test/facebook/test_default.rb
95
93
  - test/facebook/test_error.rb
96
94
  - test/facebook/test_handler.rb
97
- - test/facebook/test_load_config.rb
98
95
  - test/facebook/test_misc.rb
99
96
  - test/facebook/test_oauth.rb
100
97
  - test/facebook/test_old.rb
@@ -102,8 +99,9 @@ files:
102
99
  - test/facebook/test_parse.rb
103
100
  - test/facebook/test_serialize.rb
104
101
  - test/facebook/test_timeout.rb
105
- - test/instagram/test_api.rb
106
- - test/twitter/test_api.rb
102
+ - test/firebase/test_firebase.rb
103
+ - test/instagram/test_instagram.rb
104
+ - test/twitter/test_twitter.rb
107
105
  homepage: https://github.com/godfat/rest-more
108
106
  licenses:
109
107
  - Apache License 2.0
@@ -129,12 +127,11 @@ signing_key:
129
127
  specification_version: 4
130
128
  summary: Various REST clients such as Facebook and Twitter built with [rest-core][].
131
129
  test_files:
132
- - test/dropbox/test_api.rb
130
+ - test/dropbox/test_dropbox.rb
133
131
  - test/facebook/test_api.rb
134
132
  - test/facebook/test_default.rb
135
133
  - test/facebook/test_error.rb
136
134
  - test/facebook/test_handler.rb
137
- - test/facebook/test_load_config.rb
138
135
  - test/facebook/test_misc.rb
139
136
  - test/facebook/test_oauth.rb
140
137
  - test/facebook/test_old.rb
@@ -142,5 +139,6 @@ test_files:
142
139
  - test/facebook/test_parse.rb
143
140
  - test/facebook/test_serialize.rb
144
141
  - test/facebook/test_timeout.rb
145
- - test/instagram/test_api.rb
146
- - test/twitter/test_api.rb
142
+ - test/firebase/test_firebase.rb
143
+ - test/instagram/test_instagram.rb
144
+ - test/twitter/test_twitter.rb
@@ -1,61 +0,0 @@
1
-
2
- require 'erb'
3
- require 'yaml'
4
-
5
- module RestCore; end
6
- module RestCore::Config
7
- extend self
8
-
9
- DefaultModuleName = 'DefaultAttributes'
10
-
11
- def load_for_rails klass, namespace=nil, app=Rails
12
- default_attributes_module(klass) # make sure the default is there
13
- # even if there's no config file
14
- root = File.expand_path(app.root)
15
- path = ["#{root}/config/rest-core.yaml", # YAML should use .yaml
16
- "#{root}/config/rest-core.yml" ].find{|p| File.exist?(p)}
17
- return if path.nil?
18
- RestCore::Config.load(klass, path, app.env, namespace)
19
- end
20
-
21
- def load klass, path, env, namespace=nil
22
- config = YAML.load(ERB.new(File.read(path)).result(binding))
23
- defaults = config[env]
24
- return false unless defaults
25
- return false unless defaults[namespace] if namespace
26
- data = if namespace
27
- defaults[namespace]
28
- else
29
- defaults
30
- end
31
- raise ArgumentError.new("#{data} is not a hash") unless
32
- data.kind_of?(Hash)
33
-
34
- default_attributes_module(klass).module_eval(
35
- data.inject(["extend self\n"]){ |r, (k, v)|
36
- # quote strings, leave others free (e.g. false, numbers, etc)
37
- r << <<-RUBY
38
- def default_#{k}
39
- #{v.inspect}
40
- end
41
- RUBY
42
- }.join, __FILE__, __LINE__)
43
- end
44
-
45
- def default_attributes_module klass
46
- mod = if klass.const_defined?(DefaultModuleName)
47
- klass.const_get(DefaultModuleName)
48
- else
49
- klass.send(:const_set, DefaultModuleName, Module.new)
50
- end
51
-
52
- singleton_class = if klass.respond_to?(:singleton_class)
53
- klass.singleton_class
54
- else
55
- class << klass; self; end
56
- end
57
-
58
- klass.send(:extend, mod) unless singleton_class < mod
59
- mod
60
- end
61
- end
@@ -1,8 +0,0 @@
1
-
2
- test:
3
- facebook:
4
- app_id: 41829
5
- secret: <%= 'r41829'.reverse %>
6
- json_response: false
7
- lang: zh-tw
8
- auto_authorize_scope: 'publish_stream'
@@ -1,39 +0,0 @@
1
-
2
- require 'rest-more/test'
3
-
4
- require 'rest-core/util/config'
5
-
6
- describe RC::Config do
7
-
8
- before do
9
- @klass = RC::Facebook.dup
10
- end
11
-
12
- after do
13
- Muack.verify
14
- end
15
-
16
- def check
17
- @klass.default_app_id .should.eq 41829
18
- @klass.default_secret .should.eq 'r41829'.reverse
19
- @klass.default_json_response.should.eq false
20
- @klass.default_lang .should.eq 'zh-tw'
21
- end
22
-
23
- should 'honor rails config' do
24
- app = Object.new
25
- mock(app).env { 'test' }
26
- mock(app).root{ File.dirname(__FILE__) }
27
- RC::Config.load_for_rails(@klass, 'facebook', app)
28
- check
29
- end
30
-
31
- should 'honor config' do
32
- RC::Config.load(
33
- @klass,
34
- "#{File.dirname(__FILE__)}/config/rest-core.yaml",
35
- 'test',
36
- 'facebook')
37
- check
38
- end
39
- end