elefeely 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efecf5adba0ce0b14a82722df98443ce9085deab
4
+ data.tar.gz: 2357d1d5ec7b7e5fb3a73393390c0b535c209227
5
+ SHA512:
6
+ metadata.gz: 2cf54d9e517d7e98a1abda90ecf0bf2f95a4f3485b217a07a3758a10f938600e4fc23ee8cdc941ff349e428828eefc673c4b8a6ea447ada28d70a02e7de3f852
7
+ data.tar.gz: 2fb00c47191fcb5ca1247dc292ebcc6eb678c4c5dc5c44c9892619cb873adbe8c68be61fc2b4f28753b33784290ef41c2fe70c104c784cec3368d268d3646a02
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/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'typhoeus', '~> 0.6.3'
5
+
6
+ group :test do
7
+ gem 'rspec', '>= 2.11'
8
+ end
9
+
10
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Raphael Weiner
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,61 @@
1
+ # Elefeely
2
+
3
+ Elefeely keeps track of your feelings for you. This Ruby gem provides the (admin) interface to speak to the the Elefeely-api, and is integrated into the [elefeely-twilio-interface](http://github.com/raphweiner/elefeely-twilio-interface).
4
+
5
+ NOTE: This is not a gem intended for public use. Functionality is limited to admins with correct credentials.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'elefeely'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install elefeely
20
+
21
+ ## Configure
22
+
23
+ Configure the gem with:
24
+
25
+ ```ruby
26
+ Elefeely.configure do |config|
27
+ config.source_key = SOURCE_KEY
28
+ config.source_secret = SOURCE_SECRET
29
+ end
30
+ ```
31
+
32
+ That's it! You're ready to talk to Elefeely.
33
+
34
+ ### Usage Examples
35
+
36
+ Verify a number:
37
+
38
+ ```ruby
39
+ Elefeely.verify_number('0123456789')
40
+ ```
41
+
42
+ Retrieve verified phone numbers:
43
+
44
+ ```ruby
45
+ Elefeely.phone_numbers
46
+ ```
47
+
48
+ Post a new feeling:
49
+
50
+ ```ruby
51
+ Elefeely.send_feeling(feeling: { source_event_id: '124156', score: 4},
52
+ uid: '4151231234')
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/elefeely.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'elefeely/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "elefeely"
8
+ spec.version = Elefeely::VERSION
9
+ spec.authors = ["Raphael Weiner"]
10
+ spec.email = ["raphael.weiner@gmail.com"]
11
+ spec.description = %q{Elefeely remembers your feelings}
12
+ spec.summary = %q{Elefeely is your ruby interface to your feelings}
13
+ spec.homepage = "http://github.com/raphael/elefeely"
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
+ end
@@ -0,0 +1,22 @@
1
+ module Elefeely
2
+ module Configurable
3
+ attr_accessor :source_key,
4
+ :source_secret
5
+
6
+ def configure
7
+ yield self
8
+
9
+ validate_credentials!
10
+ end
11
+
12
+ private
13
+
14
+ def validate_credentials!
15
+ [source_key, source_secret].each do |credential|
16
+ if credential.nil? || !credential.is_a?(String)
17
+ raise ArgumentError, "Invalid: must have a valid key and secret."
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Elefeely
2
+ VERSION = "0.0.1"
3
+ end
data/lib/elefeely.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'elefeely/configurable'
2
+
3
+ require 'json'
4
+ require 'typhoeus'
5
+ require 'openssl'
6
+
7
+
8
+ module Elefeely
9
+ extend Elefeely::Configurable
10
+
11
+ def self.phone_numbers
12
+ request(:get, phone_numbers_uri)
13
+ end
14
+
15
+ def self.send_feeling(params)
16
+ request(:post, feelings_uri, body: params)
17
+ end
18
+
19
+ def self.verify_number(phone_number)
20
+ request(:put, update_phone_number_uri(phone_number))
21
+ end
22
+
23
+ private
24
+
25
+ def self.phone_numbers_uri
26
+ uri '/phones'
27
+ end
28
+
29
+ def self.feelings_uri
30
+ uri '/feelings'
31
+ end
32
+
33
+ def self.update_phone_number_uri(phone_number)
34
+ uri "/phones/#{phone_number}"
35
+ end
36
+
37
+ def self.request(verb, *params)
38
+ response = connection.send(verb, *params)
39
+ parse_response(response)
40
+ end
41
+
42
+ def self.connection
43
+ ::Typhoeus::Request
44
+ end
45
+
46
+ def self.parse_response(response)
47
+ if response.code == 200
48
+ JSON.parse(response.body)
49
+ elsif response.code == 404
50
+ nil
51
+ else
52
+ raise response.body
53
+ end
54
+ end
55
+
56
+ def self.uri(path)
57
+ uri = "http://elefeely-api.herokuapp.com"
58
+ uri << "#{path}?source_key=#{source_key}&timestamp=#{Time.now.to_i}"
59
+ uri << "&signature=#{signature(uri)}"
60
+ end
61
+
62
+ def self.signature(uri)
63
+ validate_credentials!
64
+
65
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), source_secret, uri)
66
+ end
67
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Elefeely do
4
+ context 'with an valid credentials' do
5
+ it 'should be configurable' do
6
+ expect {
7
+ Elefeely.configure do |config|
8
+ config.source_key = '123'
9
+ config.source_secret = 'abc'
10
+ end
11
+ }.to_not raise_error
12
+ end
13
+ end
14
+
15
+ context 'with invalid credentials' do
16
+ it 'should raise argument error with no source_key' do
17
+ expect {
18
+ Elefeely.configure do |config|
19
+ config.source_key = nil
20
+ config.source_secret = 'abc'
21
+ end
22
+ }.to raise_error ArgumentError
23
+ end
24
+
25
+ it 'should raise argument error with no source_secret' do
26
+ expect {
27
+ Elefeely.configure do |config|
28
+ config.source_key = '123'
29
+ config.source_secret = nil
30
+ end
31
+ }.to raise_error ArgumentError
32
+ end
33
+ end
34
+
35
+ describe '.phone_numbers' do
36
+ context 'with valid credentials' do
37
+ before(:each) do
38
+ Elefeely.stub(:source_key).and_return('123')
39
+ Elefeely.stub(:source_secret).and_return('123')
40
+ end
41
+
42
+ it 'should return phone_numbers' do
43
+ response = OpenStruct.new(code: 200, body: ({'hello' => 'json'}).to_json)
44
+ Typhoeus.stub(/phones?/).and_return(response)
45
+
46
+ expect(Elefeely.phone_numbers).to eq ({'hello' => 'json'})
47
+ end
48
+ end
49
+
50
+ context 'without credentials' do
51
+ it 'should raise a type error' do
52
+ response = OpenStruct.new(code: 200, body: ({'hello' => 'json'}).to_json)
53
+ Typhoeus.stub(/phones?/).and_return(response)
54
+
55
+ expect { Elefeely.phone_numbers }.to raise_error ArgumentError
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '.send_feeling' do
61
+ context 'with valid credentials' do
62
+ before(:each) do
63
+ Elefeely.stub(source_key: '123', source_secret: '123')
64
+ end
65
+
66
+ it 'should return response' do
67
+ response = OpenStruct.new(code: 200, body: {'hello' => 'json'}.to_json)
68
+ Typhoeus.stub(/feelings?/).and_return(response)
69
+
70
+ expect(Elefeely.send_feeling(hi: 'hi back')).to eq('hello' => 'json')
71
+ end
72
+ end
73
+
74
+ context 'without credentials' do
75
+ it 'should raise a type error' do
76
+ response = OpenStruct.new(code: 200, body: {'hello' => 'json'}.to_json)
77
+ Typhoeus.stub(/feelings?/).and_return(response)
78
+
79
+ expect { Elefeely.send_feeling(hi: 'hi back') }.to raise_error ArgumentError
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '.verify_number' do
85
+ context 'with valid credentials' do
86
+ before(:each) do
87
+ Elefeely.stub(source_key: '123', source_secret: '123')
88
+ end
89
+
90
+ context 'and a phone number' do
91
+ it 'should return a response' do
92
+ response = OpenStruct.new(code: 200, body: {'hello' => 'json'}.to_json)
93
+ Typhoeus.stub(/phones/ => response)
94
+
95
+ expect(Elefeely.verify_number('1234567890')).to eq('hello' => 'json')
96
+ end
97
+ end
98
+ end
99
+
100
+ context 'with invalid credentials' do
101
+ it 'should raise argument error' do
102
+ expect { Elefeely.verify_number('1234567890') }.to raise_error ArgumentError
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'elefeely'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elefeely
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Raphael Weiner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-30 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
+ description: Elefeely remembers your feelings
42
+ email:
43
+ - raphael.weiner@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - elefeely.gemspec
54
+ - lib/elefeely.rb
55
+ - lib/elefeely/configurable.rb
56
+ - lib/elefeely/version.rb
57
+ - spec/elefeely_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: http://github.com/raphael/elefeely
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Elefeely is your ruby interface to your feelings
83
+ test_files:
84
+ - spec/elefeely_spec.rb
85
+ - spec/spec_helper.rb