wireio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/.rvmrc ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.2-p290@wireio"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ # if command -v bundle && [[ -s Gemfile ]]
51
+ # then
52
+ # bundle install
53
+ # fi
54
+
55
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wireio.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Tabshora, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Wireio
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'wireio'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wireio
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,44 @@
1
+ require "wireio/version"
2
+ require "restclient"
3
+ require "json"
4
+ require "signature"
5
+
6
+ module WireIO
7
+ class Client
8
+ API_VERSION = 'v1'
9
+
10
+ def initialize(public_key, private_key)
11
+ @public_key, @private_key = public_key.downcase, private_key.downcase
12
+ @base_uri = 'https://app.getwire.io'
13
+ @api_endpoint = "api/#{API_VERSION}/events"
14
+ @action = "fire.json"
15
+ end
16
+
17
+ def on(event_name, payload)
18
+ RestClient.post(construct_endpoint_for(event_name),
19
+ JSON.dump({
20
+ :payload => payload,
21
+ :auth_hash => generate_auth_hash_for(@api_endpoint, payload)
22
+ }),
23
+ :content_type => :json) { |response, _request, _result|
24
+ case response.code
25
+ when 200
26
+ true
27
+ else
28
+ false
29
+ end
30
+ }
31
+ end
32
+
33
+ private
34
+ def construct_endpoint_for(event_name)
35
+ "#{@base_uri}/#{@api_endpoint}/#{event_name}/#{@action}"
36
+ end
37
+
38
+ def generate_auth_hash_for(end_point, payload)
39
+ req = Signature::Request.new('POST', end_point, payload)
40
+ req.sign(Signature::Token.new(@public_key, @private_key))
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module WireIO
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe WireIO do
4
+ before :each do
5
+ @wio_client = WireIO::Client.new(@public_key, @private_key)
6
+ @bad_client = WireIO::Client.new(@bad_public_key, @bad_private_key)
7
+ end
8
+
9
+ it "should return true if we fired the event successfully" do
10
+ @wio_client.on('awesome-event', {
11
+ :username => 'luke'
12
+ }).should be_true
13
+ end
14
+
15
+ it "should return false if we fired the event unsuccessfully" do
16
+ @bad_client.on('awesome-event', {
17
+ :username => 'luke'
18
+ }).should_not be_true
19
+ end
20
+
21
+ it "should return the correct current api version" do
22
+ WireIO::Client::API_VERSION.should eql('v1')
23
+ end
24
+
25
+ end
@@ -0,0 +1,40 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+ require 'signature'
4
+ require 'json'
5
+ require 'wireio'
6
+
7
+ RSpec.configure do |config|
8
+ config.before(:each) do
9
+ @private_key = '66c39495adea26e246965f09'
10
+ @public_key = '9a5b4eaea5dd275c'
11
+
12
+ @bad_private_key = 'skywalker'
13
+ @bad_public_key = 'jedi'
14
+
15
+ valid_uri = 'https://app.getwire.io/api/v1/events/awesome-event/fire.json'
16
+ payload = {
17
+ :username => 'luke'
18
+ }
19
+ request = Signature::Request.new('POST', "api/#{WireIO::Client::API_VERSION}/events", payload)
20
+
21
+ auth_hash = request.sign(Signature::Token.new(@public_key, @private_key))
22
+ bad_hash = request.sign(Signature::Token.new(@bad_public_key, @bad_private_key))
23
+
24
+ ## Let's start fresh again
25
+ WebMock.reset!
26
+
27
+ ## Lock it down
28
+ WebMock.disable_net_connect!
29
+
30
+ ## Simulates a valid request to fire an event.
31
+ stub_http_request(:post, valid_uri).
32
+ with(:body => {:payload => payload, :auth_hash => auth_hash}).
33
+ to_return(:body => "200 FIRED\n", :status => 200)
34
+
35
+ ## Simulates an invalid request to fire an event.
36
+ stub_http_request(:post, valid_uri).
37
+ with(:body => {:payload => payload, :auth_hash => bad_hash}).
38
+ to_return(:body => "401 UNAUTHORIZED\n", :status => 401)
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wireio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wireio"
8
+ spec.version = WireIO::VERSION
9
+ spec.authors = ["Tabshora, Inc."]
10
+ spec.email = ["hello@getwire.io"]
11
+ spec.description = %q{Gem to consume WireIO rest api}
12
+ spec.summary = %q{WireIO rest api client}
13
+ spec.homepage = "https://github.com/wireio/wireio-gem"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake", "~> 10.0.4"
22
+ spec.add_development_dependency "webmock"
23
+ spec.add_development_dependency "rspec", "~> 2.13.0"
24
+
25
+ spec.add_dependency "signature", "~> 0.1.7"
26
+ spec.add_dependency "rest-client"
27
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wireio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tabshora, Inc.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.4
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.13.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: signature
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.1.7
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.1.7
94
+ - !ruby/object:Gem::Dependency
95
+ name: rest-client
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Gem to consume WireIO rest api
111
+ email:
112
+ - hello@getwire.io
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rvmrc
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/wireio.rb
124
+ - lib/wireio/version.rb
125
+ - spec/lib/wireio_spec.rb
126
+ - spec/spec_helper.rb
127
+ - wireio.gemspec
128
+ homepage: https://github.com/wireio/wireio-gem
129
+ licenses: []
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.24
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: WireIO rest api client
152
+ test_files:
153
+ - spec/lib/wireio_spec.rb
154
+ - spec/spec_helper.rb