evostream 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 068346818b05d9f0259cddf533796e7f5f308f97
4
+ data.tar.gz: 0ad382b15559c8b0348819116597b93d057c3686
5
+ SHA512:
6
+ metadata.gz: f5b260e21e77aeb155ba30ba499f5cddd6472211c80dcfb705af77159eae04786a870ee0de02cc920b399526eedd9edbfc1992b6d4d516e1f7cc4ed411e261f9
7
+ data.tar.gz: 508b0461bfcdd916cb51f53f3a2909c37c08d75afeb2edb31497be78f3a05253fa9d8a786011ee6f53c58664582247119b9d7475e2ab9e6d0a2c41f7e217a6d4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in evostream.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Lucas Mundim
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Evostream
2
+
3
+ Ruby wrapper for the Evostream API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'evostream'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install evostream
18
+
19
+ ## Usage
20
+
21
+ You may use the block style configuration. The following code could be placed
22
+ into a +config/initializers/evostream.rb+ when used in a Rails project.
23
+
24
+ ```ruby
25
+ # config/initializers/evostream.rb (for instance)
26
+
27
+ Evostream.configure do |config|
28
+ config.host = 'evostream.example.com'
29
+ config.port = 80
30
+ config.path_prefix = '/evo'
31
+ end
32
+
33
+ # elsewhere
34
+
35
+ client = Evostream::Client.new
36
+ client.liststreams
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/evostream.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'evostream/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "evostream"
8
+ spec.version = Evostream::VERSION
9
+ spec.authors = ["Lucas Mundim"]
10
+ spec.email = ["lucas.mundim@corp.globo.com"]
11
+ spec.description = %q{Ruby wrapper for the Evostream API}
12
+ spec.summary = spec.description
13
+ spec.homepage = "http://github.com/globocom/evostream"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_runtime_dependency "rest-client"
26
+ end
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ require 'base64'
3
+ require 'rest-client'
4
+ require 'json'
5
+
6
+ module Evostream
7
+ class Client
8
+ # Define the same set of accessors as the Evostream module
9
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
10
+
11
+ def initialize(options = {})
12
+ # Merge the config values from the module and those passed
13
+ # to the client.
14
+ merged_options = Evostream.options.merge(options)
15
+
16
+ # Copy the merged values to this client and ignore those
17
+ # not part of our configuration
18
+ Configuration::VALID_CONFIG_KEYS.each do |key|
19
+ send("#{key}=", merged_options[key])
20
+ end
21
+ end
22
+
23
+ def method_missing(method, *args)
24
+ params = !args.empty? ? encode_params(args.first) : {}
25
+ response = RestClient.get(service_url(method), { :params => params })
26
+ json = JSON.parse(response.body)
27
+ if json['status'] == 'SUCCESS'
28
+ json['data']
29
+ else
30
+ super
31
+ end
32
+ end
33
+
34
+ private
35
+ def service_url(service)
36
+ "#{base_url}/#{service}"
37
+ end
38
+
39
+ def base_url
40
+ "http://#{@host}:#{@port}#{@path_prefix}"
41
+ end
42
+
43
+ def encode_params(params)
44
+ base64_params = Base64.encode64(params.collect {|k, v| "#{k}=#{v}" }.join(' ')).chomp
45
+ { :params => base64_params }
46
+ end
47
+
48
+ end # Client
49
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ module Evostream
3
+ module Configuration
4
+ VALID_CONFIG_KEYS = [:host, :port, :path_prefix].freeze
5
+ OPTIONAL_CONFIG_KEYS = VALID_CONFIG_KEYS - [:host]
6
+
7
+ DEFAULT_PORT = 80
8
+ DEFAULT_PATH_PREFIX = ''
9
+
10
+ # Build accessor methods for every config options so we can do this, for example:
11
+ # Evostream.host = 'evostream.example.com'
12
+ attr_accessor *VALID_CONFIG_KEYS
13
+
14
+ # Make sure we have the default values set when we get 'extended'
15
+ def self.extended(base)
16
+ base.reset
17
+ end
18
+
19
+ def reset
20
+ self.port = DEFAULT_PORT
21
+ self.path_prefix = DEFAULT_PATH_PREFIX
22
+ end
23
+
24
+ # config/initializers/evostream.rb (for instance)
25
+ #
26
+ # Evostream.configure do |config|
27
+ # config.host = 'evostream.example.com'
28
+ # config.port = 80
29
+ # config.path_prefix = '/evo'
30
+ # end
31
+ #
32
+ # elsewhere
33
+ #
34
+ # client = Evostream::Client.new
35
+ #
36
+ def configure
37
+ yield self
38
+ true
39
+ end
40
+
41
+ def options
42
+ Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
43
+ end
44
+
45
+ end # Configuration
46
+ end
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ module Evostream
3
+ VERSION = "0.0.1"
4
+ end
data/lib/evostream.rb ADDED
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ require "evostream/version"
3
+ require "evostream/configuration"
4
+
5
+ module Evostream
6
+ extend Configuration
7
+
8
+ autoload :Client, "evostream/client"
9
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Evostream::Client do
5
+ subject {
6
+ Evostream::Client.new(:host => 'somehost', :path_prefix => '/some_path')
7
+ }
8
+
9
+ it "should respond to an empty liststreams" do
10
+ stub_request(:get, "http://somehost:80/some_path/liststreams").
11
+ to_return(:body => '{"data":null,"description":"","status":"SUCCESS"}')
12
+ subject.liststreams.should be_nil
13
+ end
14
+
15
+ it "should respond to a non empty liststreams" do
16
+ liststreams = '{"data":[{"appName": "evostreamms"}],"description":"Available streams","status":"SUCCESS"}'
17
+ stub_request(:get, "http://somehost:80/some_path/liststreams").
18
+ to_return(:body => liststreams)
19
+ subject.liststreams.should == JSON.parse(liststreams)['data']
20
+ end
21
+
22
+ it "should respond to a non implemented method" do
23
+ 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
26
+ end
27
+
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
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Evostream do
5
+ after do
6
+ Evostream.reset
7
+ end
8
+
9
+ describe '.configure' do
10
+ Evostream::Configuration::VALID_CONFIG_KEYS.each do |key|
11
+ it "should set the #{key}" do
12
+ Evostream.configure do |config|
13
+ config.send("#{key}=", key)
14
+ Evostream.send(key).should == key
15
+ end
16
+ end
17
+ end
18
+
19
+ Evostream::Configuration::OPTIONAL_CONFIG_KEYS.each do |key|
20
+ describe ".#{key}" do
21
+ it 'should return the default value' do
22
+ Evostream.send(key).should == Evostream::Configuration.const_get("DEFAULT_#{key.upcase}")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Evostream do
5
+ it 'should have a version number' do
6
+ Evostream::VERSION.should_not be_nil
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'evostream'
4
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evostream
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Mundim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby wrapper for the Evostream API
84
+ email:
85
+ - lucas.mundim@corp.globo.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - evostream.gemspec
98
+ - lib/evostream.rb
99
+ - lib/evostream/client.rb
100
+ - lib/evostream/configuration.rb
101
+ - lib/evostream/version.rb
102
+ - spec/client_spec.rb
103
+ - spec/configuration_spec.rb
104
+ - spec/evostream_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: http://github.com/globocom/evostream
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Ruby wrapper for the Evostream API
130
+ test_files:
131
+ - spec/client_spec.rb
132
+ - spec/configuration_spec.rb
133
+ - spec/evostream_spec.rb
134
+ - spec/spec_helper.rb