kreepr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +1 -0
- data/kreepr.gemspec +23 -0
- data/lib/kreepr.rb +43 -0
- data/lib/kreepr/configurable.rb +20 -0
- data/lib/kreepr/version.rb +3 -0
- data/spec/kreepr_spec.rb +82 -0
- data/spec/spec_helper.rb +6 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e071076646e527898e19e41e9a1b6aa4c1284231
|
4
|
+
data.tar.gz: 19e068258b5ad0adb84cbbe99ddb79345c7d8042
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9ba6c7df64bb5847683061fd2ab97a4de696699aa64123021bdb874a3ce41d4ff8d503035ae9c2b1151afd1bf20ffaa363ae41d6df5c6d76a887fdfe0056927
|
7
|
+
data.tar.gz: e5c902f7506de1ffbb128b8b6a0cd8a75ae396091e2380de31881830f9d4f7ca1f9f080a6178a91985a5b1d624a08bd017c5557062b212d1f5d7da96eeaebeaf
|
data/.gitignore
ADDED
data/Gemfile
ADDED
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,67 @@
|
|
1
|
+
# Kreepr
|
2
|
+
|
3
|
+
Kreepr is gem for consuming the Kreepr API. As defined on the [Kreepr, aka Feed Engine](http://tutorials.jumpstartlab.com/projects/feed_engine.html) project page, the API should produce JSON output and expect JSON payloads for creation and updating actions.
|
4
|
+
|
5
|
+
As an authenticated API user (using an API key) you can:
|
6
|
+
|
7
|
+
* Read any publically viewable trip feed via GET, and filter only feed items created directly on Kreepr (text)
|
8
|
+
* Read any private trip feed to which the user has access via GET, and filter only feed items created directly on Kreepr (text)
|
9
|
+
* Publish a text feed item given the appropriate arguments, via POST
|
10
|
+
|
11
|
+
### Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'kreepr'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install kreepr
|
24
|
+
|
25
|
+
### Getting Started
|
26
|
+
|
27
|
+
Let's get Kreeping!
|
28
|
+
|
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
|
+
|
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):
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Kreepr.configure do |config|
|
35
|
+
config.api_key = YOUR_API_KEY
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
That's it! You're ready to talk to Feed Engine.
|
40
|
+
|
41
|
+
### Usage Examples
|
42
|
+
|
43
|
+
Retrieve feed items for a specific trip (trip must be public, or you must have permissions to view it):
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Kreepr.feed({:username => <username>, :trip_id => <trip id>})
|
47
|
+
```
|
48
|
+
|
49
|
+
Retrieve only notes posted from Kreepr:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Kreepr.feed({:username => <username>, :trip_id => <trip id>, :only => :text})
|
53
|
+
```
|
54
|
+
|
55
|
+
Publish a text feed item given the appropriate arguments, via POST
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Kreepr.post_note({:username => <username>, :trip_id => <trip id>, :text => <text>})
|
59
|
+
```
|
60
|
+
|
61
|
+
### Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/kreepr.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 'kreepr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kreepr"
|
8
|
+
spec.version = Kreepr::VERSION
|
9
|
+
spec.authors = ["Raphael Weiner, Erin Drummond, Kyle Suss, Phil Battos"]
|
10
|
+
spec.email = ["kreeprmail@gmail.com"]
|
11
|
+
spec.description = %q{The kreepr gem consumes the kreepr app}
|
12
|
+
spec.summary = %q{The kreepr gem consumes the kreepr app}
|
13
|
+
spec.homepage = "http://github.com/raphweiner/kreepr"
|
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
|
data/lib/kreepr.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "json"
|
2
|
+
require "faraday"
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
require "kreepr/version"
|
6
|
+
require "kreepr/configurable"
|
7
|
+
|
8
|
+
module Kreepr
|
9
|
+
class << self
|
10
|
+
include Configurable
|
11
|
+
|
12
|
+
def feed(params, timeout = 10)
|
13
|
+
validate_params!(params)
|
14
|
+
response = Timeout::timeout(timeout) do
|
15
|
+
::Faraday.get(request_uri(params))
|
16
|
+
end
|
17
|
+
JSON.parse(response.body)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def validate_params!(params)
|
23
|
+
unless params[:trip_id].is_a?(String) && params[:username].is_a?(String)
|
24
|
+
raise ArgumentError, "Invalid arguments specified: #{params}. Coordinator and Trip are required."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def request_uri(params)
|
29
|
+
uri = "http://localhost:3000/api/v1/feeds/#{params[:trip_id]}?"
|
30
|
+
uri << "username=#{params[:username]}"
|
31
|
+
uri << "×tamp=#{Time.now.to_i}"
|
32
|
+
uri << "&text_only=#{params[:text_only]}" if params[:text_only]
|
33
|
+
|
34
|
+
signature = encrypted_token(uri)
|
35
|
+
|
36
|
+
uri << "&signature=#{signature}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def encrypted_token(uri)
|
40
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), api_key.to_s, uri)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
data/spec/kreepr_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kreepr do
|
4
|
+
context 'with an api_key of valid type' do
|
5
|
+
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'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with an api_key of invalid type' do
|
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
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.feed' do
|
25
|
+
let(:params) { {:username => 'ebdrummond', :trip_id => '1', :text_only => true} }
|
26
|
+
|
27
|
+
context 'with invalid input' do
|
28
|
+
it 'should raise an argument error without a username' do
|
29
|
+
params[:username] = nil
|
30
|
+
expect { Kreepr.feed(params) }.to raise_error ArgumentError
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise an argument error with an invalid username type' do
|
34
|
+
params[:username] = 1234
|
35
|
+
expect { Kreepr.feed(params) }.to raise_error ArgumentError
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should raise an argument error without a trip_id' do
|
39
|
+
params[:trip_id] = nil
|
40
|
+
expect { Kreepr.feed(params) }.to raise_error ArgumentError
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should raise an argument error with an invalid trip_id type' do
|
44
|
+
params[:trip_id] = 1234
|
45
|
+
expect { Kreepr.feed(params) }.to raise_error ArgumentError
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'does not raise an error without a :text_only flag' do
|
49
|
+
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
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kreepr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raphael Weiner, Erin Drummond, Kyle Suss, Phil Battos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-22 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: The kreepr gem consumes the kreepr app
|
42
|
+
email:
|
43
|
+
- kreeprmail@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
|
+
- kreepr.gemspec
|
54
|
+
- lib/kreepr.rb
|
55
|
+
- lib/kreepr/configurable.rb
|
56
|
+
- lib/kreepr/version.rb
|
57
|
+
- spec/kreepr_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
homepage: http://github.com/raphweiner/kreepr
|
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: The kreepr gem consumes the kreepr app
|
83
|
+
test_files:
|
84
|
+
- spec/kreepr_spec.rb
|
85
|
+
- spec/spec_helper.rb
|