kreepr 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: 7ecd04043c709326365a7868afb5b0fe33f83fff
4
- data.tar.gz: eb4b410d1f74a51346cdb34c4c8d8dc7414aaaed
3
+ metadata.gz: 6f32ac3a9da64926d4637511ee31716061427b03
4
+ data.tar.gz: 3f06d58e00cb60f3e6dda69c35bd8b48dee8267a
5
5
  SHA512:
6
- metadata.gz: 4b59bebc2d46f6440838b89f78dd257a10060099897ce874edd24d72194a9d771b3a85b64697ea27a43ea3443f27582fb8d98f220d334c5ad9b0f35be3d869d8
7
- data.tar.gz: b160df33cc65e1c54bfcebcf04f26b280e5209a9574b0a5d81bee591902bed954172d9a4cb1ae03499b09731d549f55e825007a1585cb6e501fc513273a8ff3e
6
+ metadata.gz: c15a4140afd1f1afa4574b040578cb21e070176224cb6cdbe12fd76a2fca4ad8a5e4fb2b6a72215118ecc5cb4b903b37010d09d15191bf74024dd1cc7a7d6915
7
+ data.tar.gz: 911daa55d7b23091c9ce8f1ed8f3537f6cb99d633da21ddfe3f3002972fa55cd1e85f0b3f60ac68e1b9a3054be6623eba1faddf27be3b2f3979d5571178173a0
data/README.md CHANGED
@@ -28,12 +28,10 @@ Let's get Kreeping!
28
28
 
29
29
  First, you'll need to [create a Kreepr account](http://kreepr.com/), then navigate to your [account page](http://kreepr.com/account) to retrieve your API key.
30
30
 
31
- Once you have your key, configure the gem by setting your API key as such (in a Rails app, this could be put in config/initializers/kreepr.rb):
31
+ Once you have your key, configure the gem by setting your API key as such:
32
32
 
33
33
  ```ruby
34
- Kreepr.configure do |config|
35
- config.api_key = YOUR_API_KEY
36
- end
34
+ client = Kreepr::Client.new(:api_key => <your api key>)
37
35
  ```
38
36
 
39
37
  That's it! You're ready to talk to Feed Engine.
@@ -43,19 +41,19 @@ That's it! You're ready to talk to Feed Engine.
43
41
  Retrieve feed items for a specific trip (trip must be public, or you must have permissions to view it):
44
42
 
45
43
  ```ruby
46
- Kreepr.feed({:username => <username>, :trip_id => <trip id>})
44
+ client.feed(:username => <username>, :trip_id => <trip id>)
47
45
  ```
48
46
 
49
47
  Retrieve only notes posted from Kreepr:
50
48
 
51
49
  ```ruby
52
- Kreepr.feed({:username => <username>, :trip_id => <trip id>, :only => :text})
50
+ client.feed(:username => <username>, :trip_id => <trip id>, :only => :text)
53
51
  ```
54
52
 
55
- Publish a text feed item given the appropriate arguments, via POST
53
+ Publish a text feed item given the appropriate arguments, via POST. (Next version)
56
54
 
57
55
  ```ruby
58
- Kreepr.post_note({:username => <username>, :trip_id => <trip id>, :text => <text>})
56
+ client.post_note(:username => <username>, :trip_id => <trip id>, :text => <text>)
59
57
  ```
60
58
 
61
59
  ### Contributing
@@ -3,11 +3,15 @@ require "faraday"
3
3
  require "openssl"
4
4
 
5
5
  require "kreepr/version"
6
- require "kreepr/configurable"
7
6
 
8
7
  module Kreepr
9
- class << self
10
- include Configurable
8
+ class Client
9
+ attr_reader :api_key
10
+
11
+ def initialize(params)
12
+ @api_key = params[:api_key]
13
+ validate_api_key!(@api_key)
14
+ end
11
15
 
12
16
  def feed(params, timeout = 10)
13
17
  validate_params!(params)
@@ -19,7 +23,15 @@ module Kreepr
19
23
  JSON.parse(response.body)
20
24
  end
21
25
 
22
- private
26
+ private
27
+
28
+ def validate_api_key!(api_key)
29
+ if !api_key.nil?
30
+ unless api_key.is_a?(String) || api_key.is_a?(Symbol)
31
+ raise ArgumentError, "Invalid api_key specified: #{api_key} must be a string or symbol."
32
+ end
33
+ end
34
+ end
23
35
 
24
36
  def validate_params!(params)
25
37
  unless params[:trip_id].is_a?(String) && params[:username].is_a?(String)
@@ -1,3 +1,3 @@
1
1
  module Kreepr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,23 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Kreepr do
4
+ subject do
5
+ Kreepr::Client.new(:api_key => '123')
6
+ end
7
+
4
8
  context 'with an api_key of valid type' do
5
9
  it 'should be configurable' do
6
- Kreepr.configure do |config|
7
- config.api_key = "abc_123"
8
- end
9
-
10
- expect(Kreepr.api_key).to eq 'abc_123'
10
+ expect(subject.api_key).to eq '123'
11
11
  end
12
12
  end
13
13
 
14
14
  context 'with an api_key of invalid type' do
15
15
  it 'should raise an argument error' do
16
- expect {
17
- Kreepr.configure do |config|
18
- config.api_key = {"abc_123" => :hello}
19
- end
20
- }.to raise_error ArgumentError
16
+ expect { Kreepr::Client.new(12345) }.to raise_error TypeError
21
17
  end
22
18
  end
23
19
 
@@ -27,55 +23,27 @@ describe Kreepr do
27
23
  context 'with invalid input' do
28
24
  it 'should raise an argument error without a username' do
29
25
  params[:username] = nil
30
- expect { Kreepr.feed(params) }.to raise_error ArgumentError
26
+ expect { subject.feed(params) }.to raise_error ArgumentError
31
27
  end
32
28
 
33
29
  it 'should raise an argument error with an invalid username type' do
34
30
  params[:username] = 1234
35
- expect { Kreepr.feed(params) }.to raise_error ArgumentError
31
+ expect { subject.feed(params) }.to raise_error ArgumentError
36
32
  end
37
33
 
38
34
  it 'should raise an argument error without a trip_id' do
39
35
  params[:trip_id] = nil
40
- expect { Kreepr.feed(params) }.to raise_error ArgumentError
36
+ expect { subject.feed(params) }.to raise_error ArgumentError
41
37
  end
42
38
 
43
39
  it 'should raise an argument error with an invalid trip_id type' do
44
40
  params[:trip_id] = 1234
45
- expect { Kreepr.feed(params) }.to raise_error ArgumentError
41
+ expect { subject.feed(params) }.to raise_error ArgumentError
46
42
  end
47
43
 
48
44
  it 'does not raise an error without a :text_only flag' do
49
45
  params.delete(:text_only)
50
- expect { Kreepr.feed(params) }.to_not raise_error ArgumentError
51
- end
52
- end
53
-
54
- context 'with valid input' do
55
- context 'but invalid or missing api_key' do
56
- let(:bad_auth_response) do
57
- JSON.parse('{ "errors": [ { "message":"Bad Authentication data","code":215 } ] }')
58
- end
59
-
60
- it 'receives an bad authentication error' do
61
- expect(Kreepr.feed(params)).to eq bad_auth_response
62
- end
63
- end
64
-
65
- context 'with a valid api_key' do
66
- let(:params) { {:username => 'ebdrummond', :trip_id => '1', :text_only => true} }
67
-
68
- context 'to a public trip' do
69
- it 'returns the feed'
70
- end
71
-
72
- context 'to a private trip I have access to' do
73
- it 'returns the feed'
74
- end
75
-
76
- context 'to a private trip I do not have access to' do
77
- it 'raises an error'
78
- end
46
+ expect { subject.feed(params) }.to_not raise_error ArgumentError
79
47
  end
80
48
  end
81
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kreepr
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
  - Raphael Weiner, Erin Drummond, Kyle Suss, Phil Battos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-22 00:00:00.000000000 Z
11
+ date: 2013-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,6 @@ files:
52
52
  - Rakefile
53
53
  - kreepr.gemspec
54
54
  - lib/kreepr.rb
55
- - lib/kreepr/configurable.rb
56
55
  - lib/kreepr/version.rb
57
56
  - spec/kreepr_spec.rb
58
57
  - spec/spec_helper.rb
@@ -1,20 +0,0 @@
1
- module Kreepr
2
- module Configurable
3
- attr_accessor :api_key
4
-
5
- def configure
6
- yield self
7
- validate_key_type!
8
- end
9
-
10
- private
11
-
12
- def validate_key_type!
13
- if !api_key.nil?
14
- unless api_key.is_a?(String) || api_key.is_a?(Symbol)
15
- raise ArgumentError, "Invalid api_key specified: #{api_key} must be a string or symbol."
16
- end
17
- end
18
- end
19
- end
20
- end