rest-more 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.gitmodules +3 -0
- data/.travis.yml +13 -0
- data/CHANGES.md +7 -0
- data/Gemfile +26 -0
- data/LICENSE +201 -0
- data/README.md +72 -0
- data/Rakefile +63 -0
- data/TODO.md +14 -0
- data/example/rails2/Gemfile +21 -0
- data/example/rails2/README +4 -0
- data/example/rails2/Rakefile +11 -0
- data/example/rails2/app/controllers/application_controller.rb +134 -0
- data/example/rails2/app/views/application/helper.html.erb +2 -0
- data/example/rails2/config/boot.rb +130 -0
- data/example/rails2/config/environment.rb +15 -0
- data/example/rails2/config/environments/development.rb +17 -0
- data/example/rails2/config/environments/production.rb +28 -0
- data/example/rails2/config/environments/test.rb +30 -0
- data/example/rails2/config/initializers/cookie_verification_secret.rb +7 -0
- data/example/rails2/config/initializers/new_rails_defaults.rb +21 -0
- data/example/rails2/config/initializers/session_store.rb +15 -0
- data/example/rails2/config/preinitializer.rb +23 -0
- data/example/rails2/config/rest-core.yaml +16 -0
- data/example/rails2/config/routes.rb +43 -0
- data/example/rails2/log +0 -0
- data/example/rails2/test/functional/application_controller_test.rb +219 -0
- data/example/rails2/test/test_helper.rb +18 -0
- data/example/rails2/test/unit/rails_util_test.rb +44 -0
- data/example/rails3/Gemfile +20 -0
- data/example/rails3/README +4 -0
- data/example/rails3/Rakefile +7 -0
- data/example/rails3/app/controllers/application_controller.rb +134 -0
- data/example/rails3/app/views/application/helper.html.erb +2 -0
- data/example/rails3/config.ru +4 -0
- data/example/rails3/config/application.rb +23 -0
- data/example/rails3/config/boot.rb +6 -0
- data/example/rails3/config/environment.rb +5 -0
- data/example/rails3/config/environments/development.rb +23 -0
- data/example/rails3/config/environments/production.rb +49 -0
- data/example/rails3/config/environments/test.rb +30 -0
- data/example/rails3/config/initializers/secret_token.rb +7 -0
- data/example/rails3/config/initializers/session_store.rb +8 -0
- data/example/rails3/config/rest-core.yaml +16 -0
- data/example/rails3/config/routes.rb +5 -0
- data/example/rails3/test/functional/application_controller_test.rb +219 -0
- data/example/rails3/test/test_helper.rb +18 -0
- data/example/rails3/test/unit/rails_util_test.rb +44 -0
- data/example/sinatra/config.ru +16 -0
- data/lib/rest-core/client/facebook.rb +265 -0
- data/lib/rest-core/client/facebook/rails_util.rb +334 -0
- data/lib/rest-core/client/flurry.rb +107 -0
- data/lib/rest-core/client/flurry/rails_util.rb +74 -0
- data/lib/rest-core/client/github.rb +18 -0
- data/lib/rest-core/client/linkedin.rb +59 -0
- data/lib/rest-core/client/mixi.rb +47 -0
- data/lib/rest-core/client/simple.rb +2 -0
- data/lib/rest-core/client/twitter.rb +101 -0
- data/lib/rest-core/client/universal.rb +18 -0
- data/lib/rest-more.rb +11 -0
- data/lib/rest-more/version.rb +4 -0
- data/rest-more.gemspec +127 -0
- data/task/.gitignore +1 -0
- data/task/gemgem.rb +265 -0
- data/test/client/facebook/config/rest-core.yaml +8 -0
- data/test/client/facebook/test_api.rb +97 -0
- data/test/client/facebook/test_cache.rb +58 -0
- data/test/client/facebook/test_default.rb +23 -0
- data/test/client/facebook/test_error.rb +65 -0
- data/test/client/facebook/test_handler.rb +84 -0
- data/test/client/facebook/test_load_config.rb +39 -0
- data/test/client/facebook/test_misc.rb +72 -0
- data/test/client/facebook/test_oauth.rb +38 -0
- data/test/client/facebook/test_old.rb +114 -0
- data/test/client/facebook/test_page.rb +106 -0
- data/test/client/facebook/test_parse.rb +166 -0
- data/test/client/facebook/test_serialize.rb +43 -0
- data/test/client/facebook/test_timeout.rb +22 -0
- data/test/client/flurry/test_metrics.rb +83 -0
- data/test/client/twitter/test_api.rb +37 -0
- metadata +155 -0
data/rest-more.gemspec
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "rest-more"
|
5
|
+
s.version = "0.7.0"
|
6
|
+
|
7
|
+
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 = "2011-10-08"
|
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"]
|
14
|
+
s.files = [
|
15
|
+
".gitignore",
|
16
|
+
".gitmodules",
|
17
|
+
".travis.yml",
|
18
|
+
"CHANGES.md",
|
19
|
+
"Gemfile",
|
20
|
+
"LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"TODO.md",
|
24
|
+
"example/rails2/Gemfile",
|
25
|
+
"example/rails2/README",
|
26
|
+
"example/rails2/Rakefile",
|
27
|
+
"example/rails2/app/controllers/application_controller.rb",
|
28
|
+
"example/rails2/app/views/application/helper.html.erb",
|
29
|
+
"example/rails2/config/boot.rb",
|
30
|
+
"example/rails2/config/environment.rb",
|
31
|
+
"example/rails2/config/environments/development.rb",
|
32
|
+
"example/rails2/config/environments/production.rb",
|
33
|
+
"example/rails2/config/environments/test.rb",
|
34
|
+
"example/rails2/config/initializers/cookie_verification_secret.rb",
|
35
|
+
"example/rails2/config/initializers/new_rails_defaults.rb",
|
36
|
+
"example/rails2/config/initializers/session_store.rb",
|
37
|
+
"example/rails2/config/preinitializer.rb",
|
38
|
+
"example/rails2/config/rest-core.yaml",
|
39
|
+
"example/rails2/config/routes.rb",
|
40
|
+
"example/rails2/log",
|
41
|
+
"example/rails2/test/functional/application_controller_test.rb",
|
42
|
+
"example/rails2/test/test_helper.rb",
|
43
|
+
"example/rails2/test/unit/rails_util_test.rb",
|
44
|
+
"example/rails3/Gemfile",
|
45
|
+
"example/rails3/README",
|
46
|
+
"example/rails3/Rakefile",
|
47
|
+
"example/rails3/app/controllers/application_controller.rb",
|
48
|
+
"example/rails3/app/views/application/helper.html.erb",
|
49
|
+
"example/rails3/config.ru",
|
50
|
+
"example/rails3/config/application.rb",
|
51
|
+
"example/rails3/config/boot.rb",
|
52
|
+
"example/rails3/config/environment.rb",
|
53
|
+
"example/rails3/config/environments/development.rb",
|
54
|
+
"example/rails3/config/environments/production.rb",
|
55
|
+
"example/rails3/config/environments/test.rb",
|
56
|
+
"example/rails3/config/initializers/secret_token.rb",
|
57
|
+
"example/rails3/config/initializers/session_store.rb",
|
58
|
+
"example/rails3/config/rest-core.yaml",
|
59
|
+
"example/rails3/config/routes.rb",
|
60
|
+
"example/rails3/test/functional/application_controller_test.rb",
|
61
|
+
"example/rails3/test/test_helper.rb",
|
62
|
+
"example/rails3/test/unit/rails_util_test.rb",
|
63
|
+
"example/sinatra/config.ru",
|
64
|
+
"lib/rest-core/client/facebook.rb",
|
65
|
+
"lib/rest-core/client/facebook/rails_util.rb",
|
66
|
+
"lib/rest-core/client/flurry.rb",
|
67
|
+
"lib/rest-core/client/flurry/rails_util.rb",
|
68
|
+
"lib/rest-core/client/github.rb",
|
69
|
+
"lib/rest-core/client/linkedin.rb",
|
70
|
+
"lib/rest-core/client/mixi.rb",
|
71
|
+
"lib/rest-core/client/simple.rb",
|
72
|
+
"lib/rest-core/client/twitter.rb",
|
73
|
+
"lib/rest-core/client/universal.rb",
|
74
|
+
"lib/rest-more.rb",
|
75
|
+
"lib/rest-more/version.rb",
|
76
|
+
"rest-more.gemspec",
|
77
|
+
"task/.gitignore",
|
78
|
+
"task/gemgem.rb",
|
79
|
+
"test/client/facebook/config/rest-core.yaml",
|
80
|
+
"test/client/facebook/test_api.rb",
|
81
|
+
"test/client/facebook/test_cache.rb",
|
82
|
+
"test/client/facebook/test_default.rb",
|
83
|
+
"test/client/facebook/test_error.rb",
|
84
|
+
"test/client/facebook/test_handler.rb",
|
85
|
+
"test/client/facebook/test_load_config.rb",
|
86
|
+
"test/client/facebook/test_misc.rb",
|
87
|
+
"test/client/facebook/test_oauth.rb",
|
88
|
+
"test/client/facebook/test_old.rb",
|
89
|
+
"test/client/facebook/test_page.rb",
|
90
|
+
"test/client/facebook/test_parse.rb",
|
91
|
+
"test/client/facebook/test_serialize.rb",
|
92
|
+
"test/client/facebook/test_timeout.rb",
|
93
|
+
"test/client/flurry/test_metrics.rb",
|
94
|
+
"test/client/twitter/test_api.rb"]
|
95
|
+
s.homepage = "https://github.com/cardinalblue/rest-more"
|
96
|
+
s.require_paths = ["lib"]
|
97
|
+
s.rubygems_version = "1.8.11"
|
98
|
+
s.summary = "Various REST clients such as Facebook and Twitter built with [rest-core][]"
|
99
|
+
s.test_files = [
|
100
|
+
"test/client/facebook/test_api.rb",
|
101
|
+
"test/client/facebook/test_cache.rb",
|
102
|
+
"test/client/facebook/test_default.rb",
|
103
|
+
"test/client/facebook/test_error.rb",
|
104
|
+
"test/client/facebook/test_handler.rb",
|
105
|
+
"test/client/facebook/test_load_config.rb",
|
106
|
+
"test/client/facebook/test_misc.rb",
|
107
|
+
"test/client/facebook/test_oauth.rb",
|
108
|
+
"test/client/facebook/test_old.rb",
|
109
|
+
"test/client/facebook/test_page.rb",
|
110
|
+
"test/client/facebook/test_parse.rb",
|
111
|
+
"test/client/facebook/test_serialize.rb",
|
112
|
+
"test/client/facebook/test_timeout.rb",
|
113
|
+
"test/client/flurry/test_metrics.rb",
|
114
|
+
"test/client/twitter/test_api.rb"]
|
115
|
+
|
116
|
+
if s.respond_to? :specification_version then
|
117
|
+
s.specification_version = 3
|
118
|
+
|
119
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
120
|
+
s.add_runtime_dependency(%q<rest-core>, [">= 0"])
|
121
|
+
else
|
122
|
+
s.add_dependency(%q<rest-core>, [">= 0"])
|
123
|
+
end
|
124
|
+
else
|
125
|
+
s.add_dependency(%q<rest-core>, [">= 0"])
|
126
|
+
end
|
127
|
+
end
|
data/task/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.rbc
|
data/task/gemgem.rb
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Gemgem
|
5
|
+
class << self
|
6
|
+
attr_accessor :dir, :spec
|
7
|
+
end
|
8
|
+
|
9
|
+
module_function
|
10
|
+
def create
|
11
|
+
yield(spec = Gem::Specification.new{ |s|
|
12
|
+
s.authors = ['Lin Jen-Shin (godfat)']
|
13
|
+
s.email = ['godfat (XD) godfat.org']
|
14
|
+
|
15
|
+
s.description = description.join
|
16
|
+
s.summary = description.first
|
17
|
+
|
18
|
+
s.rubygems_version = Gem::VERSION
|
19
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
20
|
+
s.files = gem_files
|
21
|
+
s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
|
22
|
+
s.executables = Dir['bin/*'].map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = %w[lib]
|
24
|
+
})
|
25
|
+
spec.homepage ||= "https://github.com/godfat/#{spec.name}"
|
26
|
+
spec
|
27
|
+
end
|
28
|
+
|
29
|
+
def readme
|
30
|
+
path = %w[README.md README].find{ |name|
|
31
|
+
File.exist?("#{Gemgem.dir}/#{name}")
|
32
|
+
}
|
33
|
+
@readme ||=
|
34
|
+
if path
|
35
|
+
ps = File.read(path).scan(/#+[^\n]+\n\n.+?(?=\n\n#+[^\n]+\n)/m)
|
36
|
+
ps.inject({'HEADER' => ps.first}){ |r, s, i|
|
37
|
+
r[s[/\w+/]] = s
|
38
|
+
r
|
39
|
+
}
|
40
|
+
else
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def description
|
46
|
+
@description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
def changes
|
50
|
+
path = %w[CHANGES.md CHANGES].find{ |name|
|
51
|
+
File.exist?("#{Gemgem.dir}/#{name}")
|
52
|
+
}
|
53
|
+
@changes ||=
|
54
|
+
if path
|
55
|
+
date = '\d+{4}\-\d+{2}\-\d{2}'
|
56
|
+
File.read(path).match(
|
57
|
+
/([^\n]+#{date}\n\n(.+?))(?=\n\n[^\n]+#{date}\n|\Z)/m)[1]
|
58
|
+
else
|
59
|
+
''
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def ann_md
|
64
|
+
"##{readme['HEADER'].sub(/([\w\-]+)/, "[\\1](#{spec.homepage})")}\n\n" \
|
65
|
+
"##{readme['DESCRIPTION'][/[^\n]+\n\n[^\n]+/]}\n\n" \
|
66
|
+
"### CHANGES:\n\n" \
|
67
|
+
"###{changes}\n\n" \
|
68
|
+
"##{readme['INSTALLATION']}\n\n" +
|
69
|
+
if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}" else '' end
|
70
|
+
end
|
71
|
+
|
72
|
+
def ann_html
|
73
|
+
gem 'nokogiri'
|
74
|
+
gem 'kramdown'
|
75
|
+
|
76
|
+
IO.popen('kramdown', 'r+') do |md|
|
77
|
+
md.puts Gemgem.ann_md
|
78
|
+
md.close_write
|
79
|
+
require 'nokogiri'
|
80
|
+
html = Nokogiri::XML.parse("<gemgem>#{md.read}</gemgem>")
|
81
|
+
html.css('*').each{ |n| n.delete('id') }
|
82
|
+
html.root.children.to_html
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def ann_email
|
87
|
+
"#{readme['HEADER'].sub(/([\w\-]+)/, "\\1 <#{spec.homepage}>")}\n\n" \
|
88
|
+
"#{readme['DESCRIPTION']}\n\n" \
|
89
|
+
"#{readme['INSTALLATION']}\n\n" +
|
90
|
+
if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}\n\n" else '' end +
|
91
|
+
"## CHANGES:\n\n" \
|
92
|
+
"##{changes}\n\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
def gem_tag
|
96
|
+
"#{spec.name}-#{spec.version}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def write
|
100
|
+
File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
|
101
|
+
f << split_lines(spec.to_ruby) }
|
102
|
+
end
|
103
|
+
|
104
|
+
def split_lines ruby
|
105
|
+
ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
|
106
|
+
if $2.index(',')
|
107
|
+
"#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
108
|
+
else
|
109
|
+
s
|
110
|
+
end
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def all_files
|
115
|
+
@all_files ||= find_files(Pathname.new(dir)).map{ |file|
|
116
|
+
if file.to_s =~ %r{\.git/}
|
117
|
+
nil
|
118
|
+
else
|
119
|
+
file.to_s
|
120
|
+
end
|
121
|
+
}.compact.sort
|
122
|
+
end
|
123
|
+
|
124
|
+
def gem_files
|
125
|
+
@gem_files ||= all_files - ignored_files
|
126
|
+
end
|
127
|
+
|
128
|
+
def ignored_files
|
129
|
+
@ignored_file ||= all_files.select{ |path| ignore_patterns.find{ |ignore|
|
130
|
+
path =~ ignore && !git_files.include?(path)}}
|
131
|
+
end
|
132
|
+
|
133
|
+
def git_files
|
134
|
+
@git_files ||= if File.exist?("#{dir}/.git")
|
135
|
+
`git ls-files`.split("\n")
|
136
|
+
else
|
137
|
+
[]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# protected
|
142
|
+
def find_files path
|
143
|
+
path.children.select(&:file?).map{|file| file.to_s[(dir.size+1)..-1]} +
|
144
|
+
path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten
|
145
|
+
end
|
146
|
+
|
147
|
+
def ignore_patterns
|
148
|
+
@ignore_files ||= expand_patterns(
|
149
|
+
gitignore.split("\n").reject{ |pattern|
|
150
|
+
pattern.strip == ''
|
151
|
+
}).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} }
|
152
|
+
end
|
153
|
+
|
154
|
+
def expand_patterns pathes
|
155
|
+
pathes.map{ |path|
|
156
|
+
if path !~ /\*/
|
157
|
+
path
|
158
|
+
else
|
159
|
+
expand_patterns(
|
160
|
+
Dir[path] +
|
161
|
+
Pathname.new(File.dirname(path)).children.select(&:directory?).
|
162
|
+
map{ |prefix| "#{prefix}/#{File.basename(path)}" })
|
163
|
+
end
|
164
|
+
}.flatten
|
165
|
+
end
|
166
|
+
|
167
|
+
def gitignore
|
168
|
+
if File.exist?(path = "#{dir}/.gitignore")
|
169
|
+
File.read(path)
|
170
|
+
else
|
171
|
+
''
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
namespace :gem do
|
177
|
+
|
178
|
+
desc 'Install gem'
|
179
|
+
task :install => [:build] do
|
180
|
+
sh("#{Gem.ruby} -S gem install pkg/#{Gemgem.gem_tag}")
|
181
|
+
end
|
182
|
+
|
183
|
+
desc 'Build gem'
|
184
|
+
task :build => [:spec] do
|
185
|
+
sh("#{Gem.ruby} -S gem build #{Gemgem.spec.name}.gemspec")
|
186
|
+
sh("mkdir -p pkg")
|
187
|
+
sh("mv #{Gemgem.gem_tag}.gem pkg/")
|
188
|
+
end
|
189
|
+
|
190
|
+
desc 'Release gem'
|
191
|
+
task :release => [:spec, :check, :build] do
|
192
|
+
sh("git tag #{Gemgem.gem_tag}")
|
193
|
+
sh("git push")
|
194
|
+
sh("git push --tags")
|
195
|
+
sh("#{Gem.ruby} -S gem push pkg/#{Gemgem.gem_tag}.gem")
|
196
|
+
end
|
197
|
+
|
198
|
+
task :check do
|
199
|
+
ver = Gemgem.spec.version.to_s
|
200
|
+
|
201
|
+
if ENV['VERSION'].nil?
|
202
|
+
puts("\e[35mExpected " \
|
203
|
+
"\e[33mVERSION\e[35m=\e[33m#{ver}\e[m")
|
204
|
+
exit(1)
|
205
|
+
|
206
|
+
elsif ENV['VERSION'] != ver
|
207
|
+
puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
|
208
|
+
"\e[35mbut got\n " \
|
209
|
+
"\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[m")
|
210
|
+
exit(2)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
end # of gem namespace
|
215
|
+
|
216
|
+
desc 'Run tests in memory'
|
217
|
+
task :test do
|
218
|
+
require 'bacon'
|
219
|
+
Bacon.extend(Bacon::TestUnitOutput)
|
220
|
+
Bacon.summary_on_exit
|
221
|
+
$LOAD_PATH.unshift('lib')
|
222
|
+
Dir['./test/**/test_*.rb'].each{ |file| require file[0..-4] }
|
223
|
+
end
|
224
|
+
|
225
|
+
desc 'Run tests with shell'
|
226
|
+
task 'test:shell', :RUBY_OPTS do |t, args|
|
227
|
+
files = Dir['test/**/test_*.rb'].join(' ')
|
228
|
+
|
229
|
+
cmd = [Gem.ruby, args[:RUBY_OPTS],
|
230
|
+
'-I', 'lib', '-S', 'bacon', '--quiet', files]
|
231
|
+
|
232
|
+
sh(cmd.compact.join(' '))
|
233
|
+
end
|
234
|
+
|
235
|
+
desc 'Generate ann markdown'
|
236
|
+
task 'ann:md' => ['gem:spec'] do
|
237
|
+
puts Gemgem.ann_md
|
238
|
+
end
|
239
|
+
|
240
|
+
desc 'Generate ann html'
|
241
|
+
task 'ann:html' => ['gem:spec'] do
|
242
|
+
puts Gemgem.ann_html
|
243
|
+
end
|
244
|
+
|
245
|
+
desc 'Generate ann email'
|
246
|
+
task 'ann:email' => ['gem:spec'] do
|
247
|
+
puts Gemgem.ann_email
|
248
|
+
end
|
249
|
+
|
250
|
+
desc 'Generate rdoc'
|
251
|
+
task :doc => ['gem:spec'] do
|
252
|
+
sh("yardoc -o rdoc --main README.md" \
|
253
|
+
" --files #{Gemgem.spec.extra_rdoc_files.join(',')}")
|
254
|
+
end
|
255
|
+
|
256
|
+
desc 'Remove ignored files'
|
257
|
+
task :clean => ['gem:spec'] do
|
258
|
+
trash = "~/.Trash/#{Gemgem.spec.name}/"
|
259
|
+
sh "mkdir -p #{trash}" unless File.exist?(File.expand_path(trash))
|
260
|
+
Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" }
|
261
|
+
end
|
262
|
+
|
263
|
+
task :default do
|
264
|
+
puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
|
265
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
require 'rest-core/test'
|
3
|
+
|
4
|
+
describe RestCore::Facebook do
|
5
|
+
after do
|
6
|
+
WebMock.reset!
|
7
|
+
RR.verify
|
8
|
+
end
|
9
|
+
|
10
|
+
should 'generate correct url' do
|
11
|
+
TestHelper.normalize_url(
|
12
|
+
RestCore::Facebook.new(:access_token => 'awesome').
|
13
|
+
url('path', :query => 'str')).should.eq \
|
14
|
+
'https://graph.facebook.com/path?access_token=awesome&query=str'
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'request to correct server' do
|
18
|
+
stub_request(:get, 'http://nothing.godfat.org/me').with(
|
19
|
+
:headers => {'Accept' => 'text/plain',
|
20
|
+
'Accept-Language' => 'zh-tw',
|
21
|
+
'Accept-Encoding' => 'gzip, deflate', # this is by ruby
|
22
|
+
}.merge(RUBY_VERSION < '1.9.2' ?
|
23
|
+
{} :
|
24
|
+
{'User-Agent' => 'Ruby'})). # this is by ruby
|
25
|
+
to_return(:body => '{"data": []}')
|
26
|
+
|
27
|
+
RestCore::Facebook.new(:site => 'http://nothing.godfat.org/',
|
28
|
+
:lang => 'zh-tw',
|
29
|
+
:accept => 'text/plain').
|
30
|
+
get('me').should.eq({'data' => []})
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'pass custom headers' do
|
34
|
+
stub_request(:get, 'http://example.com/').with(
|
35
|
+
:headers => {'Accept' => 'application/json',
|
36
|
+
'Accept-Language' => 'en-us',
|
37
|
+
'Accept-Encoding' => 'gzip, deflate', # this is by ruby
|
38
|
+
'X-Forwarded-For' => '127.0.0.1',
|
39
|
+
}.merge(RUBY_VERSION < '1.9.2' ?
|
40
|
+
{} :
|
41
|
+
{'User-Agent' => 'Ruby'})). # this is by ruby
|
42
|
+
to_return(:body => '{"data": []}')
|
43
|
+
|
44
|
+
RestCore::Facebook.new.get('http://example.com', {},
|
45
|
+
{:headers => {'X-Forwarded-For' => '127.0.0.1'}} ).
|
46
|
+
should.eq({'data' => []})
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'post right' do
|
50
|
+
stub_request(:post, 'https://graph.facebook.com/feed/me').
|
51
|
+
with(:body => 'message=hi%20there').to_return(:body => 'ok')
|
52
|
+
|
53
|
+
RestCore::Facebook.new(:json_decode => false).
|
54
|
+
post('feed/me', :message => 'hi there').should == 'ok'
|
55
|
+
end
|
56
|
+
|
57
|
+
should 'use secret_access_token' do
|
58
|
+
stub_request(:get,
|
59
|
+
'https://graph.facebook.com/me?access_token=1|2').
|
60
|
+
to_return(:body => 'ok')
|
61
|
+
|
62
|
+
rg = RestCore::Facebook.new(
|
63
|
+
:json_decode => false, :access_token => 'wrong',
|
64
|
+
:app_id => '1', :secret => '2')
|
65
|
+
rg.get('me', {}, :secret => true).should.eq 'ok'
|
66
|
+
rg.url('me', {}, :secret => true).should.eq \
|
67
|
+
'https://graph.facebook.com/me?access_token=1%7C2'
|
68
|
+
rg.url('me', {}, :secret => true, :site => '/').should.eq \
|
69
|
+
'/me?access_token=1%7C2'
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'suppress auto-decode in an api call' do
|
73
|
+
stub_request(:get, 'https://graph.facebook.com/woot').
|
74
|
+
to_return(:body => 'bad json')
|
75
|
+
|
76
|
+
rg = RestCore::Facebook.new(:json_decode => true)
|
77
|
+
rg.get('woot', {}, :json_decode => false).should.eq 'bad json'
|
78
|
+
rg.json_decode.should == true
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'not raise exception when encountering error' do
|
82
|
+
[500, 401, 402, 403].each{ |status|
|
83
|
+
stub_request(:delete, 'https://graph.facebook.com/123').to_return(
|
84
|
+
:body => '[]', :status => status)
|
85
|
+
|
86
|
+
RestCore::Facebook.new.delete('123').should.eq []
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
should 'convert query to string' do
|
91
|
+
stub(o = Object.new).to_s{ 'i am mock' }
|
92
|
+
stub_request(:get, "https://graph.facebook.com/search?q=i%20am%20mock").
|
93
|
+
to_return(:body => 'ok')
|
94
|
+
RestCore::Facebook.new(:json_decode => false).
|
95
|
+
get('search', :q => o).should.eq 'ok'
|
96
|
+
end
|
97
|
+
end
|