rest-more 2.0.4 → 3.0.0

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.
Files changed (43) hide show
  1. checksums.yaml +6 -6
  2. data/.gitignore +1 -2
  3. data/.gitmodules +1 -1
  4. data/.travis.yml +5 -4
  5. data/CHANGES.md +1 -1
  6. data/Gemfile +16 -10
  7. data/README.md +209 -44
  8. data/Rakefile +11 -22
  9. data/doc/{tutorial/facebook.md → facebook.md} +1 -1
  10. data/example/multi.rb +3 -3
  11. data/example/rails3/Gemfile +18 -8
  12. data/example/rails3/app/controllers/application_controller.rb +2 -5
  13. data/example/rails3/config/application.rb +1 -1
  14. data/example/rails3/test/functional/application_controller_test.rb +0 -12
  15. data/example/rails3/test/test_helper.rb +12 -5
  16. data/example/rails3/test/unit/rails_util_test.rb +1 -6
  17. data/example/simple.rb +2 -2
  18. data/lib/rest-core/client/firebase.rb +50 -0
  19. data/lib/rest-core/client/instagram.rb +59 -0
  20. data/lib/rest-core/client/linkedin.rb +0 -4
  21. data/lib/rest-more.rb +8 -6
  22. data/lib/rest-more/test.rb +0 -11
  23. data/lib/rest-more/version.rb +1 -1
  24. data/rest-more.gemspec +20 -17
  25. data/task/README.md +54 -0
  26. data/task/gemgem.rb +151 -156
  27. data/test/dropbox/test_api.rb +1 -1
  28. data/test/facebook/test_api.rb +6 -7
  29. data/test/facebook/test_error.rb +1 -1
  30. data/test/facebook/test_handler.rb +2 -2
  31. data/test/facebook/test_load_config.rb +1 -1
  32. data/test/facebook/test_misc.rb +4 -14
  33. data/test/facebook/test_oauth.rb +1 -1
  34. data/test/facebook/test_old.rb +1 -1
  35. data/test/facebook/test_page.rb +4 -5
  36. data/test/facebook/test_parse.rb +0 -7
  37. data/test/facebook/test_serialize.rb +1 -1
  38. data/test/facebook/test_timeout.rb +4 -4
  39. data/test/instagram/test_api.rb +54 -0
  40. data/test/twitter/test_api.rb +1 -1
  41. metadata +26 -23
  42. data/example/rainbows.rb +0 -67
  43. data/task/.gitignore +0 -1
data/Rakefile CHANGED
@@ -1,34 +1,23 @@
1
- # encoding: utf-8
2
1
 
3
2
  begin
4
3
  require "#{dir = File.dirname(__FILE__)}/task/gemgem"
5
4
  rescue LoadError
6
- sh "git submodule update --init"
7
- exec Gem.ruby, "-S", "rake", *ARGV
5
+ sh 'git submodule update --init'
6
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
8
7
  end
9
8
 
10
- Gemgem.dir = dir
11
- ($LOAD_PATH << File.expand_path("#{Gemgem.dir}/lib" ) <<
12
- File.expand_path("#{Gemgem.dir}/rest-core/lib")).uniq!
9
+ $LOAD_PATH.unshift(File.expand_path("#{dir}/rest-core/lib"))
13
10
 
14
- desc 'Generate gemspec'
15
- task 'gem:spec' do
16
- Gemgem.spec = Gemgem.create do |s|
17
- require 'rest-more/version'
18
- s.name = 'rest-more'
19
- s.version = RestMore::VERSION
20
- s.homepage = 'https://github.com/cardinalblue/rest-more'
11
+ Gemgem.init(dir) do |s|
12
+ require 'rest-more/version'
13
+ s.name = 'rest-more'
14
+ s.version = RestMore::VERSION
15
+ s.homepage = 'https://github.com/godfat/rest-more'
21
16
 
22
- %w[rest-core].each{ |g| s.add_runtime_dependency(g, '>=2.0.3') }
17
+ %w[rest-core].each{ |g| s.add_runtime_dependency(g, '>=3.0.0') }
23
18
 
24
- s.authors = ['Cardinal Blue', 'Lin Jen-Shin (godfat)']
25
- s.email = ['dev (XD) cardinalblue.com']
26
-
27
- # exclude rest-core
28
- s.files.reject!{ |f| f.start_with?('rest-core/') }
29
- end
30
-
31
- Gemgem.write
19
+ # exclude rest-core
20
+ s.files.reject!{ |f| f.start_with?('rest-core/') }
32
21
  end
33
22
 
34
23
  module Gemgem
@@ -170,4 +170,4 @@
170
170
 
171
171
  That's it!
172
172
 
173
- 15. More information on customizing rest-more and its functions are to be found here: <https://github.com/cardinalblue/rest-more>
173
+ 15. More information on customizing rest-more and its functions are to be found here: <https://github.com/godfat/rest-more>
data/example/multi.rb CHANGED
@@ -2,16 +2,16 @@
2
2
  require 'rest-more'
3
3
 
4
4
  facebook = RC::Facebook.new(:log_method => method(:puts))
5
- puts "rest-client with threads doing concurrent requests"
5
+ puts "httpclient with threads doing concurrent requests"
6
6
  a = [facebook.get('4'), facebook.get('5')]
7
7
  puts "It's not blocking... but doing concurrent requests underneath"
8
8
  p a.map{ |r| r['name'] } # here we want the values, so it blocks here
9
9
  puts "DONE"
10
10
 
11
11
  puts "callback also works"
12
- facebook.get('6'){ |r|
12
+ facebook.get('6') do |r|
13
13
  p r['name']
14
- }
14
+ end
15
15
  puts "It's not blocking... but doing concurrent requests underneath"
16
16
  facebook.wait # we block here to wait for the request done
17
17
  puts "DONE"
@@ -1,22 +1,32 @@
1
1
 
2
- source 'http://rubygems.org'
2
+ source 'https://rubygems.org/'
3
3
 
4
- gem 'rails', '3.2.13'
4
+ gem 'rails', '3.2.16'
5
5
 
6
- gem 'rest-client' # for rest-core
7
6
  gem 'rest-core', :path => '../../rest-core'
8
7
  gem 'rest-more', :path => '../../'
9
8
 
10
- group 'test' do
11
- gem 'rr'
9
+ group :test do
10
+ gem 'muack'
12
11
  gem 'webmock'
13
12
  end
14
13
 
15
- platforms(:ruby) do
14
+ platforms :ruby do
16
15
  gem 'yajl-ruby'
17
- gem 'psych' # why?
18
16
  end
19
17
 
20
- platforms(:jruby) do
18
+ platforms :jruby do
21
19
  gem 'jruby-openssl'
22
20
  end
21
+
22
+ platforms :rbx do
23
+ gem 'rubysl-fiber' # used in rest-core
24
+ gem 'rubysl-weakref' # used in rest-core
25
+ gem 'rubysl-singleton' # used in rake
26
+ gem 'rubysl-rexml' # used in crack used in webmock
27
+ gem 'rubysl-bigdecimal' # used in crack used in webmock
28
+ gem 'rubysl-test-unit' # used in activesupport
29
+ gem 'rubysl-enumerator' # used in activesupport
30
+ gem 'rubysl-benchmark' # used in activesupport
31
+ gem 'racc' # used in journey used in actionpack
32
+ end
@@ -41,11 +41,8 @@ class ApplicationController < ActionController::Base
41
41
  url = rc_facebook.url('cache')
42
42
  rc_facebook.get('cache').tap{}
43
43
  rc_facebook.get('cache').tap{}
44
- key = RC::Cache.new(nil, nil, nil).cache_key(
45
- rc_facebook.dry.call(
46
- RC::REQUEST_METHOD => :get,
47
- RC::REQUEST_PATH => rc_facebook.url('cache'),
48
- &RC::Middleware.id))
44
+ res = rc_facebook.request_full(RC::REQUEST_PATH => url)
45
+ key = RC::Cache.new(nil, nil, nil).cache_key(res)
49
46
  render :text => Rails.cache.read(key)
50
47
  end
51
48
 
@@ -15,7 +15,7 @@ module Rails3
15
15
 
16
16
  logger = Logger.new($stdout)
17
17
  logger.level = Logger::INFO
18
- config.logger = logger
18
+ config.logger = logger if $DEBUG
19
19
 
20
20
  # Configure sensitive parameters which will be filtered from the log file.
21
21
  config.filter_parameters += [:password]
@@ -1,14 +1,7 @@
1
1
 
2
2
  require 'test_helper'
3
- require 'webmock'
4
- require 'rr'
5
-
6
- WebMock.disable_net_connect!
7
3
 
8
4
  class ApplicationControllerTest < ActionController::TestCase
9
- include WebMock::API
10
- include RR::Adapters::TestUnit
11
-
12
5
  def setup
13
6
  body = rand(2) == 0 ? '{"error":{"type":"OAuthException"}}' :
14
7
  '{"error_code":104}'
@@ -17,11 +10,6 @@ class ApplicationControllerTest < ActionController::TestCase
17
10
  to_return(:body => body)
18
11
  end
19
12
 
20
- def teardown
21
- RR.verify
22
- WebMock.reset!
23
- end
24
-
25
13
  def assert_url expected
26
14
  assert_equal(expected, normalize_url(assigns(:rc_facebook_authorize_url)))
27
15
  if @response.status == 200 # js redirect
@@ -1,13 +1,20 @@
1
1
 
2
2
  ENV["RAILS_ENV"] = "test"
3
3
  require File.expand_path('../../config/environment', __FILE__)
4
- begin
5
- require 'rails/test_help'
6
- rescue LoadError # for rails2
7
- require 'test_help'
8
- end
4
+ require 'rails/test_help'
5
+ require 'webmock'
6
+ WebMock.disable_net_connect!
7
+ require 'muack'
9
8
 
10
9
  class ActiveSupport::TestCase
10
+ include WebMock::API
11
+ include Muack::API
12
+
13
+ teardown do
14
+ WebMock.reset!
15
+ Muack.verify
16
+ end
17
+
11
18
  def normalize_query query, amp='&'
12
19
  '?' + query[1..-1].split(amp).sort.join(amp)
13
20
  end
@@ -1,10 +1,7 @@
1
1
 
2
2
  require 'test_helper'
3
- require 'rr'
4
3
 
5
4
  class RailsUtilTest < ActiveSupport::TestCase
6
- include RR::Adapters::TestUnit
7
-
8
5
  def setup_mock url
9
6
  @controller = Class.new do
10
7
  def self.helper dummy ; end
@@ -12,9 +9,7 @@ class RailsUtilTest < ActiveSupport::TestCase
12
9
  include RestCore::Facebook::RailsUtil
13
10
  end.new
14
11
  mock(@controller).rc_facebook_in_canvas?{ false }
15
- mock(@controller).request{
16
- mock(Object.new).url{ url }
17
- }
12
+ mock(@controller).request{ mock.url{ url }.object }
18
13
  end
19
14
 
20
15
  def test_rest_graph_normalized_request_uri_0
data/example/simple.rb CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rest-more'
3
3
 
4
- p RC::Twitter.new.statuses('_cardinalblue').first # get user tweets
4
+ p RC::Twitter.new.statuses('godfat').first # get user tweets
5
5
  puts
6
- p RC::Github.new.get('users/cardinalblue') # get user info
6
+ p RC::Github.new.get('users/godfat') # get user info
7
7
  puts
8
8
  p RC::Facebook.new.get('4') # get user info
@@ -0,0 +1,50 @@
1
+
2
+ require 'rest-core'
3
+
4
+ # https://www.firebase.com/docs/security/custom-login.html
5
+ # https://www.firebase.com/docs/rest-api.html
6
+ module RestCore
7
+ Firebase = Builder.client(:d, :secret, :auth) do
8
+ use Timeout , 10
9
+
10
+ use DefaultSite , 'https://SampleChat.firebaseIO-demo.com/'
11
+ use DefaultHeaders, {'Accept' => 'application/json'}
12
+ use DefaultQuery , nil
13
+
14
+ use CommonLogger , nil
15
+ use Cache , nil, 600 do
16
+ use ErrorHandler, lambda{ |env|
17
+ RuntimeError.new(env[RESPONSE_BODY]['message'])}
18
+ use ErrorDetectorHttp
19
+ use JsonResponse, true
20
+ end
21
+ end
22
+ end
23
+
24
+ module RestCore::Firebase::Client
25
+ include RestCore
26
+
27
+ def generate_auth opts={}
28
+ header = {:typ => 'JWT', :alg => 'HS256'}
29
+ claims = {:v => 0, :iat => Time.now.to_i, :d => d}.merge(opts)
30
+ # http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-26
31
+ input = [header, claims].map{ |d| base64url(Json.encode(d)) }.join('.')
32
+ # http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-20
33
+ "#{input}.#{base64url(Hmac.sha256(secret, input))}"
34
+ end
35
+
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
+ private
43
+ def base64url str; [str].pack('m').tr('+/', '-_'); end
44
+ def default_query; {:auth => auth}; end
45
+ def default_auth ; generate_auth ; end
46
+ end
47
+
48
+ class RestCore::Firebase
49
+ include RestCore::Firebase::Client
50
+ end
@@ -0,0 +1,59 @@
1
+
2
+ require 'rest-core'
3
+
4
+ # http://instagram.com/developer/
5
+ module RestCore
6
+ Instagram = Builder.client(:client_id, :client_secret, :data) do
7
+ use Timeout , 10
8
+
9
+ use DefaultSite , 'https://api.instagram.com/'
10
+ use DefaultHeaders, {'Accept' => 'application/json'}
11
+ use DefaultQuery , nil
12
+ use Oauth2Query , nil
13
+
14
+ use CommonLogger , nil
15
+ use Cache , nil, 600 do
16
+ use ErrorHandler, lambda{ |env| RuntimeError.new(env[RESPONSE_BODY])}
17
+ use ErrorDetectorHttp
18
+ use JsonResponse, true
19
+ end
20
+ end
21
+ end
22
+
23
+ module RestCore::Instagram::Client
24
+ include RestCore
25
+
26
+ def me query={}, opts={}
27
+ get('v1/users/self', query, opts)
28
+ end
29
+
30
+ def access_token
31
+ data['access_token']
32
+ end
33
+
34
+ def access_token= token
35
+ data['access_token'] = token
36
+ end
37
+
38
+ def authorize_url query={}, opts={}
39
+ url('oauth/authorize', {:access_token => false,
40
+ :response_type => 'code'}.merge(query), opts)
41
+ end
42
+
43
+ def authorize! payload={}, opts={}
44
+ p = {:client_id => client_id, :client_secret => client_secret,
45
+ :grant_type => 'authorization_code' }.
46
+ merge(payload)
47
+
48
+ self.data = post('oauth/access_token', p, {:access_token => false,
49
+ :client_id => false}, opts)
50
+ end
51
+
52
+ private
53
+ def default_data ; {}; end
54
+ def default_query; {:client_id => client_id}; end
55
+ end
56
+
57
+ class RestCore::Instagram
58
+ include RestCore::Instagram::Client
59
+ end
@@ -30,10 +30,6 @@ module RestCore::Linkedin::Client
30
30
  def me query={}, opts={}
31
31
  get('v1/people/~', query, opts)
32
32
  end
33
-
34
- def authorize_url
35
- url(authorize_path, :oauth_token => oauth_token, :format => false)
36
- end
37
33
  end
38
34
 
39
35
  class RestCore::Linkedin
data/lib/rest-more.rb CHANGED
@@ -2,11 +2,13 @@
2
2
  require 'rest-core'
3
3
 
4
4
  module RestCore
5
- autoload :Config , 'rest-core/util/config'
5
+ autoload :Config , 'rest-core/util/config'
6
6
 
7
- autoload :Dropbox , 'rest-core/client/dropbox'
8
- autoload :Facebook, 'rest-core/client/facebook'
9
- autoload :Github , 'rest-core/client/github'
10
- autoload :Linkedin, 'rest-core/client/linkedin'
11
- autoload :Twitter , 'rest-core/client/twitter'
7
+ autoload :Dropbox , 'rest-core/client/dropbox'
8
+ autoload :Facebook , 'rest-core/client/facebook'
9
+ autoload :Firebase , 'rest-core/client/firebase'
10
+ autoload :Github , 'rest-core/client/github'
11
+ autoload :Instagram, 'rest-core/client/instagram'
12
+ autoload :Linkedin , 'rest-core/client/linkedin'
13
+ autoload :Twitter , 'rest-core/client/twitter'
12
14
  end
@@ -1,14 +1,3 @@
1
1
 
2
2
  require 'rest-core/test'
3
3
  require 'rest-more'
4
-
5
- module TestHelper
6
- module_function
7
- def normalize_query query
8
- '?' + query[1..-1].split('&').sort.join('&')
9
- end
10
-
11
- def normalize_url url
12
- url.sub(/\?.+/){ |query| TestHelper.normalize_query(query) }
13
- end
14
- end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module RestMore
3
- VERSION = '2.0.4'
3
+ VERSION = '3.0.0'
4
4
  end
data/rest-more.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: rest-more 3.0.0 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "rest-more"
5
- s.version = "2.0.4"
6
+ s.version = "3.0.0"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = [
9
- "Cardinal Blue",
10
- "Lin Jen-Shin (godfat)"]
11
- s.date = "2013-04-13"
12
- s.description = "Various REST clients such as Facebook and Twitter built with [rest-core][]\n\n[rest-core]: https://github.com/cardinalblue/rest-core"
13
- s.email = ["dev (XD) cardinalblue.com"]
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["Lin Jen-Shin (godfat)"]
11
+ s.date = "2014-05-04"
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
+ s.email = ["godfat (XD) godfat.org"]
14
14
  s.executables = ["rib-rest-core"]
15
15
  s.files = [
16
16
  ".gitignore",
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "TODO.md",
25
25
  "bin/rib-rest-core",
26
- "doc/tutorial/facebook.md",
26
+ "doc/facebook.md",
27
27
  "example/multi.rb",
28
28
  "example/rails3/Gemfile",
29
29
  "example/rails3/README",
@@ -44,14 +44,15 @@ Gem::Specification.new do |s|
44
44
  "example/rails3/test/functional/application_controller_test.rb",
45
45
  "example/rails3/test/test_helper.rb",
46
46
  "example/rails3/test/unit/rails_util_test.rb",
47
- "example/rainbows.rb",
48
47
  "example/simple.rb",
49
48
  "example/sinatra/config.ru",
50
49
  "lib/rest-core/client/dropbox.rb",
51
50
  "lib/rest-core/client/facebook.rb",
52
51
  "lib/rest-core/client/facebook/rails_util.rb",
52
+ "lib/rest-core/client/firebase.rb",
53
53
  "lib/rest-core/client/github.rb",
54
54
  "lib/rest-core/client/github/rails_util.rb",
55
+ "lib/rest-core/client/instagram.rb",
55
56
  "lib/rest-core/client/linkedin.rb",
56
57
  "lib/rest-core/client/linkedin/rails_util.rb",
57
58
  "lib/rest-core/client/twitter.rb",
@@ -63,7 +64,7 @@ Gem::Specification.new do |s|
63
64
  "lib/rest-more/version.rb",
64
65
  "lib/rib/app/rest-core.rb",
65
66
  "rest-more.gemspec",
66
- "task/.gitignore",
67
+ "task/README.md",
67
68
  "task/gemgem.rb",
68
69
  "test/dropbox/test_api.rb",
69
70
  "test/facebook/config/rest-core.yaml",
@@ -79,11 +80,12 @@ Gem::Specification.new do |s|
79
80
  "test/facebook/test_parse.rb",
80
81
  "test/facebook/test_serialize.rb",
81
82
  "test/facebook/test_timeout.rb",
83
+ "test/instagram/test_api.rb",
82
84
  "test/twitter/test_api.rb"]
83
- s.homepage = "https://github.com/cardinalblue/rest-more"
84
- s.require_paths = ["lib"]
85
- s.rubygems_version = "2.0.0"
86
- s.summary = "Various REST clients such as Facebook and Twitter built with [rest-core][]"
85
+ s.homepage = "https://github.com/godfat/rest-more"
86
+ s.licenses = ["Apache License 2.0"]
87
+ s.rubygems_version = "2.2.2"
88
+ s.summary = "Various REST clients such as Facebook and Twitter built with [rest-core][]."
87
89
  s.test_files = [
88
90
  "test/dropbox/test_api.rb",
89
91
  "test/facebook/test_api.rb",
@@ -98,17 +100,18 @@ Gem::Specification.new do |s|
98
100
  "test/facebook/test_parse.rb",
99
101
  "test/facebook/test_serialize.rb",
100
102
  "test/facebook/test_timeout.rb",
103
+ "test/instagram/test_api.rb",
101
104
  "test/twitter/test_api.rb"]
102
105
 
103
106
  if s.respond_to? :specification_version then
104
107
  s.specification_version = 4
105
108
 
106
109
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
107
- s.add_runtime_dependency(%q<rest-core>, [">= 2.0.3"])
110
+ s.add_runtime_dependency(%q<rest-core>, [">= 3.0.0"])
108
111
  else
109
- s.add_dependency(%q<rest-core>, [">= 2.0.3"])
112
+ s.add_dependency(%q<rest-core>, [">= 3.0.0"])
110
113
  end
111
114
  else
112
- s.add_dependency(%q<rest-core>, [">= 2.0.3"])
115
+ s.add_dependency(%q<rest-core>, [">= 3.0.0"])
113
116
  end
114
117
  end