feed_burner 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a9a43d1e37f01b9a298909a4afe4a9739ef7b9c
4
+ data.tar.gz: ff2cdabaae991195865bb6e2f06395986aeca6d2
5
+ SHA512:
6
+ metadata.gz: af43bf60e8c6105b78ee717c9336fea099cad62c7619abedf048da47e34237a59f4913013060da5a64f6fc8eebdf8523976eb2cded6c2b0fa77e5e13e22dd78e
7
+ data.tar.gz: 15e784f546ee9f1867d89ed2468e9cb05f53cbbfa7b2f7dd5241437071d601885d1abe0b5aaf221afd4b736db6ad7837792d03e138a08d9ddb2678bd8163ff0a
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,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'faraday', '~> 0.8.7'
5
+
6
+ group :test do
7
+ gem 'coveralls', :require => false
8
+ gem 'rspec', '>= 2.11'
9
+ gem 'simplecov', :require => false
10
+ end
11
+
12
+ 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,68 @@
1
+ # FeedBurner
2
+
3
+ FeedBurner is gem for consuming the FeedEngine API. As defined on the [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 FeedEngine (text)
8
+ * Read any private trip feed to which the user has access via GET, and filter only feed items created directly on FeedEngine (text)
9
+ * Publish a text feed item given the appropriate arguments, via POST
10
+ * **(Remove this?)** Refeed another user’s feed item, given its id
11
+
12
+ ### Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'feed_burner'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install feed_burner
25
+
26
+ ### Getting Started
27
+
28
+ Let's get Feed Burning!
29
+
30
+ First, you'll need to [create a Feed Engine account](http://kreepr.com/), then navigate to your [account page](http://kreepr.com/account) to retrieve your API key.
31
+
32
+ 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/feed_burner.rb):
33
+
34
+ ```ruby
35
+ FeedBurner.configure do |config|
36
+ config.api_key = YOUR_API_KEY
37
+ end
38
+ ```
39
+
40
+ That's it! You're ready to talk to Feed Engine.
41
+
42
+ ### Usage Examples
43
+
44
+ Retrieve feed items for a specific trip (trip must be public, or you must have permissions to view it):
45
+
46
+ ```ruby
47
+ FeedBurner.feed({:username => <username>, :trip_id => <trip id>})
48
+ ```
49
+
50
+ Retrieve only notes posted from FeedEngine:
51
+
52
+ ```ruby
53
+ FeedBurner.feed({:username => <username>, :trip_id => <trip id>, :only => :text})
54
+ ```
55
+
56
+ Publish a text feed item given the appropriate arguments, via POST
57
+
58
+ ```ruby
59
+ FeedBurner.post_note({:username => <username>, :trip_id => <trip id>, :text => <text>})
60
+ ```
61
+
62
+ ### Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'feed_burner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "feed_burner"
8
+ spec.version = FeedBurner::VERSION
9
+ spec.authors = ["Raphael Weiner, Erin Drummond, Kyle Suss, Phil Battos"]
10
+ spec.email = ["kreeprmail@gmail.com"]
11
+ spec.description = %q{Consume the Feed Engine API}
12
+ spec.summary = %q{Feed Burner is a gem to consume the Feed Engine API}
13
+ spec.homepage = "http://github.com/raphweiner/feed_burner"
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,20 @@
1
+ module FeedBurner
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
@@ -0,0 +1,3 @@
1
+ module FeedBurner
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,41 @@
1
+ require "json"
2
+ require "faraday"
3
+ require "openssl"
4
+
5
+ require "feed_burner/version"
6
+ require "feed_burner/configurable"
7
+
8
+ module FeedBurner
9
+ class << self
10
+ include Configurable
11
+
12
+ def feed(params)
13
+ validate_params!(params)
14
+ response = ::Faraday.get(request_uri(params))
15
+ response.body
16
+ end
17
+
18
+ private
19
+
20
+ def validate_params!(params)
21
+ unless params[:trip_id].is_a?(String) && params[:username].is_a?(String)
22
+ raise ArgumentError, "Invalid arguments specified: #{params}. Coordinator and Trip are required."
23
+ end
24
+ end
25
+
26
+ def request_uri(params)
27
+ uri = "http://localhost:3000/api/v1/feeds/#{params[:trip_id]}?"
28
+ uri << "username=#{params[:username]}"
29
+ uri << "&timestamp=#{Time.now.to_i}"
30
+ uri << "&text_only=#{params[:text_only]}" if params[:text_only]
31
+
32
+ signature = encrypted_token(uri)
33
+
34
+ uri << "&signature=#{signature}"
35
+ end
36
+
37
+ def encrypted_token(uri)
38
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), api_key.to_s, uri)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,84 @@
1
+ require 'feed_burner'
2
+
3
+ describe FeedBurner do
4
+ context 'with an api_key of valid type' do
5
+ it 'should be configurable' do
6
+ FeedBurner.configure do |config|
7
+ config.api_key = "abc_123"
8
+ end
9
+
10
+ expect(FeedBurner.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
+ FeedBurner.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 { FeedBurner.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 { FeedBurner.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 { FeedBurner.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 { FeedBurner.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 { FeedBurner.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(FeedBurner.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' do
70
+ {:username => 'ebdrummond', :trip_id => '1', :text_only => true}
71
+ end
72
+ end
73
+
74
+ context 'to a private trip I have access to' do
75
+ it 'returns the feed'
76
+ end
77
+
78
+ context 'to a private trip I do not have access to' do
79
+ it 'raises an error'
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: feed_burner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
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-21 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: Consume the Feed Engine API
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
+ - feed_burner.gemspec
54
+ - lib/feed_burner.rb
55
+ - lib/feed_burner/configurable.rb
56
+ - lib/feed_burner/version.rb
57
+ - spec/feed_burner_spec.rb
58
+ homepage: http://github.com/raphweiner/feed_burner
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Feed Burner is a gem to consume the Feed Engine API
82
+ test_files:
83
+ - spec/feed_burner_spec.rb