grifter 0.0.5 → 0.0.6
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.
- data/Gemfile.lock +40 -0
- data/bin/grift +11 -2
- data/grifter.gemspec +4 -20
- metadata +4 -20
- data/Rakefile +0 -41
- data/VERSION +0 -1
- data/example/grifter.yml +0 -7
- data/example/owm_grifts/weather_grifts.rb +0 -3
- data/example/temperatures.rb +0 -12
- data/spec/configuration_spec.rb +0 -127
- data/spec/grifter_spec.rb +0 -52
- data/spec/http_service_spec.rb +0 -81
- data/spec/json_helpers_spec.rb +0 -77
- data/spec/resources/example_config.yml +0 -19
- data/spec/resources/grifter.yml +0 -11
- data/spec/resources/syntax_error_grifts/eval_error_grifts.rb +0 -3
- data/spec/resources/twitter_grifts/oauth_grifts.rb +0 -23
- data/spec/resources/twitter_grifts/timeline_grifts.rb +0 -9
- data/spec/rspec_helper_spec.rb +0 -30
- data/spec/support/require_all_lib_files.rb +0 -0
- data/spec/support/spec_helper.rb +0 -19
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
awesome_print (1.1.0)
|
5
|
+
coderay (1.0.9)
|
6
|
+
diff-lcs (1.2.4)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.8.4)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rdoc
|
13
|
+
json (1.7.7)
|
14
|
+
method_source (0.8.1)
|
15
|
+
pry (0.9.12.1)
|
16
|
+
coderay (~> 1.0.5)
|
17
|
+
method_source (~> 0.8)
|
18
|
+
slop (~> 3.4)
|
19
|
+
rake (10.0.4)
|
20
|
+
rdoc (4.0.1)
|
21
|
+
json (~> 1.4)
|
22
|
+
rspec (2.13.0)
|
23
|
+
rspec-core (~> 2.13.0)
|
24
|
+
rspec-expectations (~> 2.13.0)
|
25
|
+
rspec-mocks (~> 2.13.0)
|
26
|
+
rspec-core (2.13.1)
|
27
|
+
rspec-expectations (2.13.0)
|
28
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
29
|
+
rspec-mocks (2.13.1)
|
30
|
+
slop (3.4.4)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
awesome_print
|
37
|
+
jeweler
|
38
|
+
json
|
39
|
+
pry
|
40
|
+
rspec
|
data/bin/grift
CHANGED
@@ -27,8 +27,14 @@ def parse_cmd_line
|
|
27
27
|
opts.on("-f", "--script=FILENAME",
|
28
28
|
"specify a script file to run") { |file| options[:files] << file }
|
29
29
|
|
30
|
+
opts.on("-d", "--script-dir=dir",
|
31
|
+
"specify a directory of grift scripts, run all of them") { |dir| options[:files] += Dir["#{dir}/**/*.rb"] }
|
32
|
+
|
30
33
|
opts.on("-v", "--verbose",
|
31
|
-
"
|
34
|
+
"debug logging, see every request and response in detail") { Log.level = Logger::DEBUG }
|
35
|
+
|
36
|
+
opts.on("-q", "--verbose",
|
37
|
+
"quiet logging, warnings and errors only") { Log.level = Logger::WARN }
|
32
38
|
|
33
39
|
opts.on("-c", "--config=FILENAME",
|
34
40
|
"config filename") { |fn| options[:config_file] = fn }
|
@@ -36,7 +42,7 @@ def parse_cmd_line
|
|
36
42
|
opts.on('-e', '--environment=ENVIRONMENT',
|
37
43
|
"environment name") { |e| options[:environment] = e.to_sym }
|
38
44
|
|
39
|
-
opts.on("-
|
45
|
+
opts.on("-n", "--no_authenticate",
|
40
46
|
"Do not authenticate") { options[:authenticate] = false }
|
41
47
|
|
42
48
|
end
|
@@ -47,12 +53,15 @@ options = parse_cmd_line
|
|
47
53
|
|
48
54
|
grifter = Grifter.new options
|
49
55
|
|
56
|
+
|
50
57
|
if not(ARGV.empty?)
|
58
|
+
#a grift method has been specified on the command line
|
51
59
|
method = ARGV.shift
|
52
60
|
response = grifter.send(method.to_sym, *ARGV)
|
53
61
|
puts response.inspect
|
54
62
|
|
55
63
|
elsif not(options[:files].empty?)
|
64
|
+
#some grift files were specified on the command line?
|
56
65
|
options[:files].each do |script_file|
|
57
66
|
grifter.run_script_file(script_file)
|
58
67
|
end
|
data/grifter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "grifter"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Robert Schultheis"]
|
12
|
-
s.date = "2013-05-
|
12
|
+
s.date = "2013-05-15"
|
13
13
|
s.description = "convention based approach to interfacing with an HTTP JSON API."
|
14
14
|
s.email = "rob@knewton.com"
|
15
15
|
s.executables = ["grift"]
|
@@ -18,14 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
21
22
|
"LICENSE.txt",
|
22
|
-
"Rakefile",
|
23
23
|
"Readme.md",
|
24
|
-
"VERSION",
|
25
24
|
"bin/grift",
|
26
|
-
"example/grifter.yml",
|
27
|
-
"example/owm_grifts/weather_grifts.rb",
|
28
|
-
"example/temperatures.rb",
|
29
25
|
"grifter.gemspec",
|
30
26
|
"lib/grifter.rb",
|
31
27
|
"lib/grifter/blankslate.rb",
|
@@ -33,19 +29,7 @@ Gem::Specification.new do |s|
|
|
33
29
|
"lib/grifter/helpers.rb",
|
34
30
|
"lib/grifter/http_service.rb",
|
35
31
|
"lib/grifter/json_helpers.rb",
|
36
|
-
"lib/grifter/log.rb"
|
37
|
-
"spec/configuration_spec.rb",
|
38
|
-
"spec/grifter_spec.rb",
|
39
|
-
"spec/http_service_spec.rb",
|
40
|
-
"spec/json_helpers_spec.rb",
|
41
|
-
"spec/resources/example_config.yml",
|
42
|
-
"spec/resources/grifter.yml",
|
43
|
-
"spec/resources/syntax_error_grifts/eval_error_grifts.rb",
|
44
|
-
"spec/resources/twitter_grifts/oauth_grifts.rb",
|
45
|
-
"spec/resources/twitter_grifts/timeline_grifts.rb",
|
46
|
-
"spec/rspec_helper_spec.rb",
|
47
|
-
"spec/support/require_all_lib_files.rb",
|
48
|
-
"spec/support/spec_helper.rb"
|
32
|
+
"lib/grifter/log.rb"
|
49
33
|
]
|
50
34
|
s.homepage = "http://github.com/knewton/grifter"
|
51
35
|
s.licenses = ["MIT"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grifter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -100,14 +100,10 @@ extra_rdoc_files:
|
|
100
100
|
- LICENSE.txt
|
101
101
|
files:
|
102
102
|
- Gemfile
|
103
|
+
- Gemfile.lock
|
103
104
|
- LICENSE.txt
|
104
|
-
- Rakefile
|
105
105
|
- Readme.md
|
106
|
-
- VERSION
|
107
106
|
- bin/grift
|
108
|
-
- example/grifter.yml
|
109
|
-
- example/owm_grifts/weather_grifts.rb
|
110
|
-
- example/temperatures.rb
|
111
107
|
- grifter.gemspec
|
112
108
|
- lib/grifter.rb
|
113
109
|
- lib/grifter/blankslate.rb
|
@@ -116,18 +112,6 @@ files:
|
|
116
112
|
- lib/grifter/http_service.rb
|
117
113
|
- lib/grifter/json_helpers.rb
|
118
114
|
- lib/grifter/log.rb
|
119
|
-
- spec/configuration_spec.rb
|
120
|
-
- spec/grifter_spec.rb
|
121
|
-
- spec/http_service_spec.rb
|
122
|
-
- spec/json_helpers_spec.rb
|
123
|
-
- spec/resources/example_config.yml
|
124
|
-
- spec/resources/grifter.yml
|
125
|
-
- spec/resources/syntax_error_grifts/eval_error_grifts.rb
|
126
|
-
- spec/resources/twitter_grifts/oauth_grifts.rb
|
127
|
-
- spec/resources/twitter_grifts/timeline_grifts.rb
|
128
|
-
- spec/rspec_helper_spec.rb
|
129
|
-
- spec/support/require_all_lib_files.rb
|
130
|
-
- spec/support/spec_helper.rb
|
131
115
|
homepage: http://github.com/knewton/grifter
|
132
116
|
licenses:
|
133
117
|
- MIT
|
@@ -143,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
127
|
version: '0'
|
144
128
|
segments:
|
145
129
|
- 0
|
146
|
-
hash:
|
130
|
+
hash: 1598752812454653536
|
147
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
132
|
none: false
|
149
133
|
requirements:
|
data/Rakefile
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "grifter"
|
18
|
-
gem.homepage = "http://github.com/knewton/grifter"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Make calls to HTTP JSON APIs with ease and confidence}
|
21
|
-
gem.description = %Q{convention based approach to interfacing with an HTTP JSON API.}
|
22
|
-
gem.email = "rob@knewton.com"
|
23
|
-
gem.authors = ["Robert Schultheis"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
28
|
-
require 'rspec/core/rake_task'
|
29
|
-
RSpec::Core::RakeTask.new(:spec)
|
30
|
-
|
31
|
-
task :default => :spec
|
32
|
-
|
33
|
-
require 'rdoc/task'
|
34
|
-
Rake::RDocTask.new do |rdoc|
|
35
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
36
|
-
|
37
|
-
rdoc.rdoc_dir = 'rdoc'
|
38
|
-
rdoc.title = "grifter #{version}"
|
39
|
-
rdoc.rdoc_files.include('README*')
|
40
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.5
|
data/example/grifter.yml
DELETED
data/example/temperatures.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
[
|
2
|
-
'New York, NY',
|
3
|
-
'Toronto, Canada',
|
4
|
-
'Paris, France',
|
5
|
-
'Tokyo, Japan',
|
6
|
-
'Sydney, Australia',
|
7
|
-
].each do |city|
|
8
|
-
weather = weather_for city
|
9
|
-
kelvin = weather['main']['temp']
|
10
|
-
celcius = (kelvin - 273.15).round
|
11
|
-
puts "#{city}: #{celcius} celcius"
|
12
|
-
end
|
data/spec/configuration_spec.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
require 'grifter/configuration'
|
2
|
-
|
3
|
-
describe Grifter::Configuration do
|
4
|
-
|
5
|
-
let(:configuration) { Class.new.extend(Grifter::Configuration) }
|
6
|
-
|
7
|
-
let(:empty_config) { {} }
|
8
|
-
|
9
|
-
let (:no_service_config) { { services: {} } }
|
10
|
-
|
11
|
-
let (:single_basic_service_config) {
|
12
|
-
{
|
13
|
-
services: {
|
14
|
-
twitter: { hostname: 'twitter.com' }
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
let (:all_service_values_defined) {
|
20
|
-
{
|
21
|
-
services: {
|
22
|
-
twitter: {
|
23
|
-
hostname: 'twitter.com',
|
24
|
-
port: 8888,
|
25
|
-
ssl: true,
|
26
|
-
ignore_ssl_cert: true,
|
27
|
-
base_uri: '/api/v2',
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
describe "Service configuration normalization" do
|
34
|
-
it "should require a services block" do
|
35
|
-
expect { configuration.normalize_config empty_config }.to raise_error GrifterConfigurationError
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should require at least one service in service block" do
|
39
|
-
expect { configuration.normalize_config no_service_config }.to raise_error GrifterConfigurationError
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should default ssl, ssl_certificate_ignore, and port" do
|
43
|
-
config = configuration.normalize_config single_basic_service_config
|
44
|
-
config[:services].should eql({
|
45
|
-
twitter: {
|
46
|
-
hostname: 'twitter.com',
|
47
|
-
port: 80,
|
48
|
-
ssl: false,
|
49
|
-
ignore_ssl_cert: false,
|
50
|
-
base_uri: '',
|
51
|
-
name: 'twitter',
|
52
|
-
}}
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should allow overrides for all values" do
|
57
|
-
config = configuration.normalize_config all_service_values_defined
|
58
|
-
config.should eql(all_service_values_defined)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "loading config from a file" do
|
63
|
-
it "should allow specifying a filename" do
|
64
|
-
config = configuration.load_config_file config_file: 'spec/resources/example_config.yml'
|
65
|
-
config[:services].should eql({
|
66
|
-
myapi: {
|
67
|
-
hostname: 'myapi.com',
|
68
|
-
name: 'myapi',
|
69
|
-
port: 80,
|
70
|
-
ssl: false,
|
71
|
-
ignore_ssl_cert: false,
|
72
|
-
base_uri: '',
|
73
|
-
},
|
74
|
-
myotherapi: {
|
75
|
-
hostname: 'myotherapi.com',
|
76
|
-
name: 'myotherapi',
|
77
|
-
port: 80,
|
78
|
-
ssl: false,
|
79
|
-
ignore_ssl_cert: false,
|
80
|
-
base_uri: '',
|
81
|
-
},
|
82
|
-
})
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should take the filename from an environment variable if specified" do
|
86
|
-
ENV['GRIFTER_CONFIG_FILE'] = 'spec/resources/example_config.yml'
|
87
|
-
config = configuration.load_config_file
|
88
|
-
config[:services].keys.should =~ [:myapi, :myotherapi]
|
89
|
-
ENV['GRIFTER_CONFIG_FILE'] = nil
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "environment based overriding" do
|
94
|
-
it "should allow overriding configuration based on an environment name" do
|
95
|
-
config = configuration.load_config_file config_file: 'spec/resources/example_config.yml',
|
96
|
-
environment: :dev
|
97
|
-
config[:services].should eql({
|
98
|
-
myapi: {
|
99
|
-
hostname: 'dev.myapi.com',
|
100
|
-
name: 'myapi',
|
101
|
-
port: 123,
|
102
|
-
ssl: false,
|
103
|
-
ignore_ssl_cert: false,
|
104
|
-
base_uri: '',
|
105
|
-
},
|
106
|
-
myotherapi: {
|
107
|
-
hostname: 'myotherapi.com',
|
108
|
-
name: 'myotherapi',
|
109
|
-
port: 80,
|
110
|
-
ssl: false,
|
111
|
-
ignore_ssl_cert: false,
|
112
|
-
base_uri: '',
|
113
|
-
},
|
114
|
-
})
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should allow setting environment via an environment variable" do
|
119
|
-
ENV['GRIFTER_ENVIRONMENT'] = 'dev'
|
120
|
-
config = configuration.load_config_file config_file: 'spec/resources/example_config.yml'
|
121
|
-
|
122
|
-
config[:services][:myapi][:hostname].should eql 'dev.myapi.com'
|
123
|
-
ENV['GRIFTER_ENVIRONMENT'] = nil
|
124
|
-
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
data/spec/grifter_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'grifter'
|
2
|
-
|
3
|
-
describe Grifter do
|
4
|
-
describe "Configuration" do
|
5
|
-
it "should allow for initializing from a config file" do
|
6
|
-
grifter = Grifter.new :config_file => 'spec/resources/example_config.yml'
|
7
|
-
grifter.should respond_to(:myapi)
|
8
|
-
grifter.myapi.name.should eql('myapi')
|
9
|
-
grifter.services.any?{|s| s.name == 'myapi' }.should be_true
|
10
|
-
|
11
|
-
grifter.should respond_to(:myotherapi)
|
12
|
-
grifter.myotherapi.name.should eql('myotherapi')
|
13
|
-
grifter.services.any?{|s| s.name == 'myotherapi' }.should be_true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "Grifter files" do
|
18
|
-
it "should allow loading grifter files which define methods for interacting with apis" do
|
19
|
-
grifter = Grifter.new :config_file => 'spec/resources/grifter.yml'
|
20
|
-
grifter.should respond_to :timeline_for
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "syntax errors" do
|
24
|
-
it "should produce a nice stack trace if a grifter file has a syntax error" do
|
25
|
-
expect do
|
26
|
-
grifter = Grifter.new load_from_config_file: false,
|
27
|
-
grift_globs: ['spec/resources/syntax_error_grifts/eval_error_grifts.rb']
|
28
|
-
end.to raise_error NoMethodError
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "Authentication" do
|
34
|
-
it "when authenticate is invoked, it should call any method ending in grifter_authenticate" do
|
35
|
-
grifter = Grifter.new :config_file => 'spec/resources/example_config.yml'
|
36
|
-
grifter.define_singleton_method :test_svc_grifter_authenticate do
|
37
|
-
true
|
38
|
-
end
|
39
|
-
grifter.define_singleton_method :test_svc_grifter_authenticate_substring_only do
|
40
|
-
true
|
41
|
-
end
|
42
|
-
|
43
|
-
grifter.should_receive :test_svc_grifter_authenticate
|
44
|
-
grifter.should_not_receive :test_svc_grifter_authenticate_substring_only
|
45
|
-
|
46
|
-
grifter.grifter_authenticate_do
|
47
|
-
end
|
48
|
-
|
49
|
-
#TODO: test that ensures grifter_authenticate_do is called
|
50
|
-
# if Grifter is instantiated with :authenticate => true
|
51
|
-
end
|
52
|
-
end
|
data/spec/http_service_spec.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'grifter/http_service'
|
2
|
-
|
3
|
-
describe Grifter::HTTPService do
|
4
|
-
|
5
|
-
let(:test_configuration) do
|
6
|
-
{
|
7
|
-
name: 'test service',
|
8
|
-
hostname: 'totallyfakedomainthatcouldnotpossiblyexist.com',
|
9
|
-
port: 80,
|
10
|
-
ssl: false,
|
11
|
-
ignore_ssl_certificate: false,
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
before(:each) do
|
16
|
-
@svc = Grifter::HTTPService.new test_configuration
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "http methods" do
|
20
|
-
before(:each) do
|
21
|
-
response = Net::HTTPOK.new('1.1', 200, "stub response body")
|
22
|
-
response.stub(:body).and_return '{"foo": "bar"}'
|
23
|
-
@svc.http.stub!(:request).and_return(response)
|
24
|
-
end
|
25
|
-
|
26
|
-
#methods without a request body
|
27
|
-
[
|
28
|
-
:get,
|
29
|
-
:head,
|
30
|
-
:delete,
|
31
|
-
].each do |method|
|
32
|
-
it "should have a #{method.to_s} method" do
|
33
|
-
@svc.send(method, '/testing').should be_a Hash
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
#methods with a json request body
|
38
|
-
[
|
39
|
-
:put,
|
40
|
-
:post,
|
41
|
-
].each do |method|
|
42
|
-
it "should have a #{method.to_s} method" do
|
43
|
-
@svc.send(method, '/testing', {'a_key' => 'a_value'}).should be_a Hash
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should remember the last request and response" do
|
48
|
-
@svc.post '/testing', 'a_key' => 'a_value'
|
49
|
-
@svc.last_request.should be_a Net::HTTP::Post
|
50
|
-
@svc.last_response.should be_a Net::HTTPOK
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "error handling" do
|
55
|
-
before(:each) do
|
56
|
-
response = Net::HTTPBadRequest.new('1.1', 400, "stuff not sure what it does")
|
57
|
-
response.stub(:body).and_return '{"error_code": "400", "error_message": "bad api client, no cookies for you!"}'
|
58
|
-
@svc.http.stub!(:request).and_return(response)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should raise a RequestException when a 400 is returned" do
|
62
|
-
expect { @svc.get '/testing' }.to raise_error(Grifter::RequestException)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "default header configuration" do
|
67
|
-
it "should specification of default headers" do
|
68
|
-
svc = Grifter::HTTPService.new test_configuration.merge default_headers: { 'abc' => '123' }
|
69
|
-
response = Net::HTTPOK.new('1.1', 200, "stub response body")
|
70
|
-
response.stub(:body).and_return '{"foo": "bar"}'
|
71
|
-
svc.http.stub!(:request).and_return(response)
|
72
|
-
|
73
|
-
svc.http.should_receive(:request).with do |req|
|
74
|
-
req['abc'].should eql('123')
|
75
|
-
end
|
76
|
-
|
77
|
-
svc.get '/hello'
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/spec/json_helpers_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'grifter/json_helpers.rb'
|
2
|
-
|
3
|
-
describe Grifter::JsonHelpers do
|
4
|
-
|
5
|
-
let(:json_helper) { Class.new.extend(Grifter::JsonHelpers) }
|
6
|
-
|
7
|
-
describe :jsonify do
|
8
|
-
it "should turn a hash into json" do
|
9
|
-
hash = {
|
10
|
-
'a' => '123',
|
11
|
-
'b' => 456,
|
12
|
-
:c => [
|
13
|
-
1,
|
14
|
-
2.3,
|
15
|
-
'456'
|
16
|
-
],
|
17
|
-
'd' => {
|
18
|
-
'x' => 'y'
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
json = json_helper.jsonify(hash)
|
23
|
-
|
24
|
-
#ugh, gross!
|
25
|
-
json.should eql %Q|{
|
26
|
-
"a": "123",
|
27
|
-
"b": 456,
|
28
|
-
"c": [
|
29
|
-
1,
|
30
|
-
2.3,
|
31
|
-
"456"
|
32
|
-
],
|
33
|
-
"d": {
|
34
|
-
"x": "y"
|
35
|
-
}
|
36
|
-
}|
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should return a non json string as itself" do
|
41
|
-
json_helper.jsonify("abc").should eql("abc")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should make a json string pretty" do
|
45
|
-
json_str = '{"foo":"bar", "abc":123}'
|
46
|
-
json_helper.jsonify(json_str).should eql %Q|{
|
47
|
-
"foo": "bar",
|
48
|
-
"abc": 123
|
49
|
-
}|
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
describe :objectify do
|
55
|
-
it "should turn a json map string into a Hash" do
|
56
|
-
hsh = {'str' => 'abc', 'int' => 123, 'dec' => 12.34, 'bool' => true}
|
57
|
-
json = JSON.generate hsh
|
58
|
-
json_helper.objectify(json).should eql hsh
|
59
|
-
end
|
60
|
-
|
61
|
-
it "turn a json array string into an Array" do
|
62
|
-
arr = [1, 2.34, 'three', true]
|
63
|
-
json = JSON.generate arr
|
64
|
-
json_helper.objectify(json).should =~ arr
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should return a non-string object as itself" do
|
68
|
-
obj = 12.34
|
69
|
-
json_helper.objectify(obj).should eql obj
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return a non-json string as itself" do
|
73
|
-
str = 'abc;123'
|
74
|
-
json_helper.objectify(str).should eql str
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
---
|
2
|
-
services:
|
3
|
-
myapi:
|
4
|
-
hostname: 'myapi.com'
|
5
|
-
|
6
|
-
myotherapi:
|
7
|
-
hostname: 'myotherapi.com'
|
8
|
-
|
9
|
-
environments:
|
10
|
-
dev:
|
11
|
-
myapi:
|
12
|
-
hostname: 'dev.myapi.com'
|
13
|
-
port: 123
|
14
|
-
|
15
|
-
staging:
|
16
|
-
myapi:
|
17
|
-
hostname: 'staging.myapi.com'
|
18
|
-
port: 456
|
19
|
-
ignore_ssl_cert: true
|
data/spec/resources/grifter.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
|
3
|
-
def twitter_keys
|
4
|
-
@_twitter_keys ||= YAML.load_file('example/twitter_grifts/oauth.yml')
|
5
|
-
end
|
6
|
-
|
7
|
-
def application_authenticate
|
8
|
-
params = { 'grant_type' => 'client_credentials' }
|
9
|
-
token = twitter_keys['consumer_key'] + ':' + twitter_keys['consumer_secret']
|
10
|
-
encoded_token = Base64.strict_encode64(token)
|
11
|
-
response = twitter.post_form '/oauth2/token', params,
|
12
|
-
base_uri: '',
|
13
|
-
additional_headers: {
|
14
|
-
'Authorization' => "Basic " + encoded_token,
|
15
|
-
'Accept' => '*/*', # I think this is a bug that I have to set it to this: https://dev.twitter.com/discussions/16348#comment-36465
|
16
|
-
}
|
17
|
-
twitter.headers['Authorization'] = "Bearer #{response['access_token']}"
|
18
|
-
true
|
19
|
-
end
|
20
|
-
|
21
|
-
def twitter_grift
|
22
|
-
application_authenticate
|
23
|
-
end
|
data/spec/rspec_helper_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'grifter'
|
2
|
-
require 'grifter/helpers'
|
3
|
-
|
4
|
-
describe Grifter::Helpers do
|
5
|
-
describe "including" do
|
6
|
-
it "should be includable" do
|
7
|
-
mod = Module.new do
|
8
|
-
ENV['GRIFTER_CONFIG_FILE'] = 'spec/resources/grifter.yml'
|
9
|
-
include Grifter::Helpers
|
10
|
-
end
|
11
|
-
|
12
|
-
cla = Class.new do
|
13
|
-
extend mod
|
14
|
-
end
|
15
|
-
|
16
|
-
cla.should respond_to :grifter
|
17
|
-
|
18
|
-
#should return the grifter instance if requested
|
19
|
-
cla.grifter.should be_a Grifter
|
20
|
-
cla.grifter.should respond_to :timeline_for
|
21
|
-
|
22
|
-
#but better, all grift methods are just available as is
|
23
|
-
cla.should respond_to :timeline_for
|
24
|
-
|
25
|
-
#the raw services should be available
|
26
|
-
cla.should respond_to :twitter
|
27
|
-
cla.twitter.should respond_to :get
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
File without changes
|
data/spec/support/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
2
|
-
RSpec.configure do |config|
|
3
|
-
#config.treat_symbols_as_metadata_keys_with_true_values = true
|
4
|
-
|
5
|
-
#setting this to false ensure if we screw up a tag, nothing will run
|
6
|
-
# and we'll know a tag is screwed up.
|
7
|
-
config.run_all_when_everything_filtered = false
|
8
|
-
|
9
|
-
# removing this bit of config as it will interfere with our custom tagging scheme
|
10
|
-
#config.filter_run :focus
|
11
|
-
|
12
|
-
# Run specs in random order to surface order dependencies. If you find an
|
13
|
-
# order dependency and want to debug it, you can fix the order by providing
|
14
|
-
# the seed, which is printed after each run.
|
15
|
-
# --seed 1234
|
16
|
-
# config.order = 'random'
|
17
|
-
|
18
|
-
#config.include TestDataHelpers
|
19
|
-
end
|