elefeely 0.0.1 → 0.0.2

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: efecf5adba0ce0b14a82722df98443ce9085deab
4
- data.tar.gz: 2357d1d5ec7b7e5fb3a73393390c0b535c209227
3
+ metadata.gz: 6e500d5d500e43c80b90dc3310f61468befcbdef
4
+ data.tar.gz: 99ca2f6120def23bc97d37d4a486c49cd4a5fdf9
5
5
  SHA512:
6
- metadata.gz: 2cf54d9e517d7e98a1abda90ecf0bf2f95a4f3485b217a07a3758a10f938600e4fc23ee8cdc941ff349e428828eefc673c4b8a6ea447ada28d70a02e7de3f852
7
- data.tar.gz: 2fb00c47191fcb5ca1247dc292ebcc6eb678c4c5dc5c44c9892619cb873adbe8c68be61fc2b4f28753b33784290ef41c2fe70c104c784cec3368d268d3646a02
6
+ metadata.gz: 33ff496a104a55c4004b5fcf6abf1bc6d57fbfff1809dd4a678ea1a7097824bf5a6b08bbaa782ee13794c815c3c33e489eaaad15f7275f50818a2153eba7dab0
7
+ data.tar.gz: ccafd1362dcf56432005f0e1c8ca0d37051493752adf6eba11dae4acce7209ff97dd8fd7ef590f20e5a7135a9856529f719951f45864b5b6ab61fc5b07330d99
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Code Climate](https://codeclimate.com/github/raphweiner/elefeely.png)](https://codeclimate.com/github/raphweiner/elefeely)
2
+
3
+
1
4
  # Elefeely
2
5
 
3
6
  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).
@@ -23,10 +26,8 @@ Or install it yourself as:
23
26
  Configure the gem with:
24
27
 
25
28
  ```ruby
26
- Elefeely.configure do |config|
27
- config.source_key = SOURCE_KEY
28
- config.source_secret = SOURCE_SECRET
29
- end
29
+ Elefeely.configure(source_key: YOUR SOURCE KEY,
30
+ source_secret: YOUR SOURCE SECRET)
30
31
  ```
31
32
 
32
33
  That's it! You're ready to talk to Elefeely.
@@ -52,6 +53,12 @@ Elefeely.send_feeling(feeling: { source_event_id: '124156', score: 4},
52
53
  uid: '4151231234')
53
54
  ```
54
55
 
56
+ Unsubscribe a number:
57
+
58
+ ```ruby
59
+ Elefeely.unsubscribe_number('0123456789')
60
+ ```
61
+
55
62
  ## Contributing
56
63
 
57
64
  1. Fork it
@@ -3,8 +3,9 @@ module Elefeely
3
3
  attr_accessor :source_key,
4
4
  :source_secret
5
5
 
6
- def configure
7
- yield self
6
+ def configure(params)
7
+ self.source_key = params[:source_key]
8
+ self.source_secret = params[:source_secret]
8
9
 
9
10
  validate_credentials!
10
11
  end
@@ -14,9 +15,12 @@ module Elefeely
14
15
  def validate_credentials!
15
16
  [source_key, source_secret].each do |credential|
16
17
  if credential.nil? || !credential.is_a?(String)
17
- raise ArgumentError, "Invalid: must have a valid key and secret."
18
+ raise InvalidCredentials
18
19
  end
19
20
  end
20
21
  end
22
+
21
23
  end
22
24
  end
25
+
26
+ class InvalidCredentials < RuntimeError; end
@@ -1,3 +1,3 @@
1
1
  module Elefeely
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/elefeely.rb CHANGED
@@ -17,7 +17,11 @@ module Elefeely
17
17
  end
18
18
 
19
19
  def self.verify_number(phone_number)
20
- request(:put, update_phone_number_uri(phone_number))
20
+ request(:put, update_phone_number_uri(phone_number), body: {verified: true})
21
+ end
22
+
23
+ def self.unsubscribe_number(phone_number)
24
+ request(:put, update_phone_number_uri(phone_number), body: {verified: false})
21
25
  end
22
26
 
23
27
  private
@@ -62,6 +66,6 @@ private
62
66
  def self.signature(uri)
63
67
  validate_credentials!
64
68
 
65
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), source_secret, uri)
69
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha512'), source_secret, uri)
66
70
  end
67
71
  end
@@ -4,10 +4,7 @@ describe Elefeely do
4
4
  context 'with an valid credentials' do
5
5
  it 'should be configurable' do
6
6
  expect {
7
- Elefeely.configure do |config|
8
- config.source_key = '123'
9
- config.source_secret = 'abc'
10
- end
7
+ Elefeely.configure(source_key: '123', source_secret: 'abc')
11
8
  }.to_not raise_error
12
9
  end
13
10
  end
@@ -15,24 +12,23 @@ describe Elefeely do
15
12
  context 'with invalid credentials' do
16
13
  it 'should raise argument error with no source_key' do
17
14
  expect {
18
- Elefeely.configure do |config|
19
- config.source_key = nil
20
- config.source_secret = 'abc'
21
- end
22
- }.to raise_error ArgumentError
15
+ Elefeely.configure(source_key: nil, source_secret: 'abc')
16
+ }.to raise_error InvalidCredentials
23
17
  end
24
18
 
25
19
  it 'should raise argument error with no source_secret' do
26
20
  expect {
27
- Elefeely.configure do |config|
28
- config.source_key = '123'
29
- config.source_secret = nil
30
- end
31
- }.to raise_error ArgumentError
21
+ Elefeely.configure(source_key: '123', source_secret: nil)
22
+ }.to raise_error InvalidCredentials
32
23
  end
33
24
  end
34
25
 
35
26
  describe '.phone_numbers' do
27
+ before(:all) do
28
+ response = OpenStruct.new(code: 200, body: ({'hello' => 'json'}).to_json)
29
+ Typhoeus.stub(/phones?/).and_return(response)
30
+ end
31
+
36
32
  context 'with valid credentials' do
37
33
  before(:each) do
38
34
  Elefeely.stub(:source_key).and_return('123')
@@ -40,43 +36,33 @@ describe Elefeely do
40
36
  end
41
37
 
42
38
  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
39
  expect(Elefeely.phone_numbers).to eq ({'hello' => 'json'})
47
40
  end
48
41
  end
49
42
 
50
43
  context 'without credentials' do
51
44
  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
45
+ expect { Elefeely.phone_numbers }.to raise_error InvalidCredentials
56
46
  end
57
47
  end
58
48
  end
59
49
 
60
50
  describe '.send_feeling' do
61
51
  context 'with valid credentials' do
62
- before(:each) do
52
+ before(:all) do
63
53
  Elefeely.stub(source_key: '123', source_secret: '123')
64
- end
65
-
66
- it 'should return response' do
67
54
  response = OpenStruct.new(code: 200, body: {'hello' => 'json'}.to_json)
68
55
  Typhoeus.stub(/feelings?/).and_return(response)
56
+ end
69
57
 
58
+ it 'should return response' do
70
59
  expect(Elefeely.send_feeling(hi: 'hi back')).to eq('hello' => 'json')
71
60
  end
72
61
  end
73
62
 
74
63
  context 'without credentials' do
75
64
  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
65
+ expect { Elefeely.send_feeling(hi: 'hi back') }.to raise_error InvalidCredentials
80
66
  end
81
67
  end
82
68
  end
@@ -85,21 +71,40 @@ describe Elefeely do
85
71
  context 'with valid credentials' do
86
72
  before(:each) do
87
73
  Elefeely.stub(source_key: '123', source_secret: '123')
74
+ response = OpenStruct.new(code: 200, body: {'hello' => 'json'}.to_json)
75
+ Typhoeus.stub(/phones/ => response)
88
76
  end
89
77
 
90
- context 'and a phone number' do
78
+ context 'and phone number' do
91
79
  it 'should return a response' do
92
- response = OpenStruct.new(code: 200, body: {'hello' => 'json'}.to_json)
93
- Typhoeus.stub(/phones/ => response)
94
-
95
80
  expect(Elefeely.verify_number('1234567890')).to eq('hello' => 'json')
96
81
  end
97
82
  end
83
+
84
+ context 'without a phone number' do
85
+ it 'should not raise an argument error' do
86
+ expect(Elefeely.verify_number(nil)).to_not raise_error InvalidCredentials
87
+ end
88
+ end
98
89
  end
99
90
 
100
- context 'with invalid credentials' do
91
+ context 'without credentials' do
101
92
  it 'should raise argument error' do
102
- expect { Elefeely.verify_number('1234567890') }.to raise_error ArgumentError
93
+ expect { Elefeely.verify_number('1234567890') }.to raise_error InvalidCredentials
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '.unsubscribe_number' do
99
+ before(:each) do
100
+ Elefeely.stub(source_key: '123', source_secret: '123')
101
+ response = OpenStruct.new(code: 200, body: {'hello' => 'json'}.to_json)
102
+ Typhoeus.stub(/phones/ => response)
103
+ end
104
+
105
+ context 'with valid credentials' do
106
+ it 'should return a response' do
107
+ expect(Elefeely.unsubscribe_number('1234567890')).to eq('hello' => 'json')
103
108
  end
104
109
  end
105
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elefeely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphael Weiner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-30 00:00:00.000000000 Z
11
+ date: 2013-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler