evostream 0.0.2 → 0.0.3

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: 2cdd1c79b2ffd46742f13ea245d2f517037583ce
4
- data.tar.gz: 6be888eda78740456c97dea11044ef35a8462845
3
+ metadata.gz: ebca9c1de8b04b344b8121a4cedf391a1862e277
4
+ data.tar.gz: 3cac40b9818ea7285d8f738dae1bb53449dcfc31
5
5
  SHA512:
6
- metadata.gz: 07301944d677ed583f27b3f1b94662f0363c7657d098a57101d0ceae05f2d09e32cd3122296601d557feef6e16c51f579819b0ebd6dd6c282531c19a6c885de0
7
- data.tar.gz: 7e2848125e2848358b2d65f4a769cfcc1209b3ac5821be7f1dba7132d607a1c393f7b6c40d084a7536e731ba3254759f60cd90a39884adacf1a599f50c9ec0f9
6
+ metadata.gz: 6e2f8b84d2dd842b0ddc44c8c8c14d331d4aabc848dd58c17dedd053b7e4eecb38a599b93a0afa46c381dc0e426b1922dffb98d6af70046608b9545f430961a3
7
+ data.tar.gz: 878b924abbf7ede2608927a414ee649df4bbd9a538a86268ed7bbb0e1e810d28fca3ea7b0a05fe0183c7ec8c3e084dd4a43ad9cdee413c9ac6355768c9d64631
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ evostream
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/evostream.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "debugger"
25
26
  end
@@ -20,18 +20,22 @@ module Evostream
20
20
  end
21
21
  end
22
22
 
23
+ private
23
24
  def method_missing(method, *args)
24
25
  params = !args.empty? ? args.first : {}
25
26
  response = api_call(method, params)
26
- json = JSON.parse(response.body)
27
- if json['status'] == 'SUCCESS'
28
- json['data']
27
+ if response.code.to_i == 200
28
+ json = parse(response.body)
29
+ if json['status'] == 'SUCCESS'
30
+ json['data']
31
+ else
32
+ super
33
+ end
29
34
  else
30
- super
35
+ raise response.body
31
36
  end
32
37
  end
33
38
 
34
- private
35
39
  def api_call(method, params)
36
40
  url = URI.parse(service_url(method, params))
37
41
  request = Net::HTTP::Get.new(url.to_s)
@@ -58,5 +62,10 @@ module Evostream
58
62
  Base64.encode64(params.map {|k, v| "#{k}=#{v}" }.join(' ')).chomp
59
63
  end
60
64
 
65
+ def parse(text)
66
+ JSON.parse(text)
67
+ rescue JSON::ParserError => ex
68
+ raise "Invalid response: #{ex.message}"
69
+ end
61
70
  end # Client
62
71
  end
@@ -1,4 +1,4 @@
1
1
  # coding: utf-8
2
2
  module Evostream
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
data/spec/client_spec.rb CHANGED
@@ -6,28 +6,54 @@ describe Evostream::Client do
6
6
  Evostream::Client.new(:host => 'somehost', :path_prefix => '/some_path')
7
7
  }
8
8
 
9
- it "should respond to an empty liststreams" do
9
+ it "should handle a SUCCESS response with null data" do
10
10
  stub_request(:get, "http://somehost:80/some_path/liststreams").
11
- to_return(:body => '{"data":null,"description":"","status":"SUCCESS"}')
11
+ to_return(status: 200, body: '{"data":null,"description":"Available streams","status":"SUCCESS"}')
12
12
  subject.liststreams.should be_nil
13
13
  end
14
14
 
15
- it "should respond to a non empty liststreams" do
15
+ it "should handle a SUCCESS response with data" do
16
16
  liststreams = '{"data":[{"appName": "evostreamms"}],"description":"Available streams","status":"SUCCESS"}'
17
17
  stub_request(:get, "http://somehost:80/some_path/liststreams").
18
- to_return(:body => liststreams)
18
+ to_return(status: 200, body: liststreams)
19
19
  subject.liststreams.should == JSON.parse(liststreams)['data']
20
20
  end
21
21
 
22
- it "should respond to a non implemented method" do
22
+ it "should handle a FAIL response to a non existant service" do
23
+ stub_request(:get, "http://somehost:80/some_path/non_existant_service").
24
+ to_return(status: 200, body: '{"data":null,"description":"command non_existant_service not known. Type help for list of commands","status":"FAIL"}')
25
+ expect { subject.non_existant_service }.to raise_error(NoMethodError)
26
+ end
27
+
28
+ it "should rescue from an unexpected response" do
29
+ stub_request(:get, "http://somehost:80/some_path/liststreams").
30
+ to_return(status: 200, body: '<html><head><title>It works!</title></head><body>It works!</body></html>')
31
+ expect { subject.liststreams }.to raise_error(/^Invalid response:/)
32
+ end
33
+
34
+ it "should handle a 500 response" do
23
35
  stub_request(:get, "http://somehost:80/some_path/liststreams").
24
- to_return(:body => '{"data":null,"description":"command non_existant_service not known. Type help for list of commands","status":"FAIL"}')
25
- expect { subject.non_existant_service }.to raise_error
36
+ to_return(status: 500, body: 'Internal server error')
37
+ expect { subject.liststreams }.to raise_error('Internal server error')
38
+ end
39
+
40
+ it "should handle a 404 response" do
41
+ stub_request(:get, "http://somehost:80/some_path/liststreams").
42
+ to_return(status: 404, body: 'Not found')
43
+ expect { subject.liststreams }.to raise_error('Not found')
44
+ end
45
+
46
+ it "should encode params as symbols with base64" do
47
+ stub_request(:get, /.*some_service.*/).
48
+ to_return(status: 200, body: '{"data":null,"description":"","status":"SUCCESS"}')
49
+ subject.some_service(:first_param => 'xxx', :second_param => 'xxx')
50
+ WebMock.should have_requested(:get, "http://somehost:80/some_path/some_service?params=Zmlyc3RfcGFyYW09eHh4IHNlY29uZF9wYXJhbT14eHg=")
26
51
  end
27
52
 
28
- it "should encode params with base64" do
29
- stub_request(:get, "http://somehost:80/some_path/some_service?params=Zmlyc3RfcGFyYW09eHh4IHNlY29uZF9wYXJhbT14eHg=").
30
- to_return(:body => '{"data":null,"description":"","status":"SUCCESS"}')
31
- subject.some_service(:first_param => 'xxx', :second_param => 'xxx').should be_nil
53
+ it "should encode params as strings with base64" do
54
+ stub_request(:get, /.*some_service.*/).
55
+ to_return(status: 200, body: '{"data":null,"description":"","status":"SUCCESS"}')
56
+ subject.some_service('first_param' => 'xxx', 'second_param' => 'xxx')
57
+ WebMock.should have_requested(:get, "http://somehost:80/some_path/some_service?params=Zmlyc3RfcGFyYW09eHh4IHNlY29uZF9wYXJhbT14eHg=")
32
58
  end
33
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evostream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Mundim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-02 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: debugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Ruby wrapper for the Evostream API
70
84
  email:
71
85
  - lucas.mundim@corp.globo.com
@@ -75,6 +89,8 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - .gitignore
77
91
  - .rspec
92
+ - .ruby-gemset
93
+ - .ruby-version
78
94
  - .travis.yml
79
95
  - Gemfile
80
96
  - LICENSE.txt