streetcred 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
- module Streetcred
2
- VERSION = "0.0.2"
1
+ module StreetCred
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/streetcred.rb CHANGED
@@ -1,17 +1,53 @@
1
- require "streetcred/version"
1
+ require 'streetcred/version'
2
+ require 'koala'
2
3
 
3
4
  module StreetCred
4
- class HANDLER
5
+ class Handler
5
6
 
6
- def initialize
7
+ def initialize(app_id, app_secret)
8
+ @app_id = app_id
9
+ @app_secret = app_secret
7
10
  end
8
11
 
9
- def generate_status_ticket
10
- status_ticket = Hash.new
12
+ # handles a hash of params, and responds with response hash
13
+ def handle(params)
14
+ validate_signed_request(params[:signed_request])
15
+
16
+ if params[:order_status]
17
+ product_info = {
18
+ 'method' => 'pay',
19
+ 'title' => 'My Awsome Virtual Item',
20
+ 'description' => 'Best. Virtual Item. Ever.',
21
+ 'image_url' => "http://2.bp.blogspot.com/-nqAn1B4aRxo/TxNmL93PoAI/AAAAAAAACvU/t0N5_6r7ds8/s1600/pid1534-dog_bowl_hi_res.jpg",
22
+ 'product_url' => 'google.com/dogs',
23
+ 'price' => 1,
24
+ 'item_id' => 'MY_ITEM_ID'
25
+ }
26
+ response = {
27
+ 'content' => [product_info],
28
+ 'method' => 'payments_get_items'
29
+ }
30
+ else
31
+ response = {
32
+ 'method' => 'payments_status_update',
33
+ 'order_id' => '1234',
34
+ 'status' => 'settled',
35
+ }
36
+ end
37
+
38
+ response
11
39
  end
12
-
13
- def self.hello_world
14
- "hello world"
40
+
41
+ private
42
+
43
+ # uses koala to validate the signed_request with APP_ID and APP_SECRET
44
+ def validate_signed_request(signed_request)
45
+ begin
46
+ oauth = Koala::Facebook::OAuth.new(@app_id, @app_secret)
47
+ parsed_signed_request = oauth.parse_signed_request(signed_request)
48
+ rescue
49
+ raise ArgumentError, 'unable to validate signed_request'
50
+ end
15
51
  end
16
52
 
17
53
  end
data/readme.md CHANGED
@@ -1 +1 @@
1
- This is just a test I'm using to learn to work with open-source projects.
1
+ This is project I'm currently working on. Eventually, it should help you handle Facebook credit callback actions in Rails apps.
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'Although not required, bundler is recommended for running the tests.'
5
+ end
6
+
7
+ require 'rubygems'
8
+ require 'streetcred'
9
+
10
+ RSpec.configure do |config|
11
+ # some (optional) config here
12
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'StreetCred::Handler' do
4
+
5
+ APP_ID = '362948877094549'
6
+ APP_SECRET = 'secret'
7
+
8
+ SIGNED_REQUEST = 'bmlgEbd0aQ6-WykWVQyGvT2Y5UWjyjfThMJKgF1IJDY.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNyZWRpdHMiOnsiYnV5ZXIiOjExNjE5OTA0NzksInJlY2VpdmVyIjoxMTYxOTkwNDc5LCJvcmRlcl9pZCI6Mzk1Njc0MzQzODU3Mjk1LCJvcmRlcl9pbmZvIjoiXCJPUkRFUl9JTkZPXCIiLCJ0ZXN0X21vZGUiOjF9LCJleHBpcmVzIjoxMzU4Nzk4NDAwLCJpc3N1ZWRfYXQiOjEzNTg3OTM0NTcsIm9hdXRoX3Rva2VuIjoiQUFBRktHWkE3a0RwVUJBSnpIRVJzdU8wVXozWkJSemFncXVWb284YlAxR1NrWkNtNThiSU83SkNqTElkVlZNNEE3VU1OM1pDR0kwTktHNzlrZG1UeDZjVzM0OVpDWkJNc25aQlJmeDUxdVlUSVBKNlJIVGg0MXhUIiwidXNlciI6eyJjb3VudHJ5IjoidXMiLCJsb2NhbGUiOiJlbl9VUyIsImFnZSI6eyJtaW4iOjIxfX0sInVzZXJfaWQiOiIxMTYxOTkwNDc5In0'
9
+
10
+ it "can be initialized" do
11
+ handler = StreetCred::Handler.new(APP_ID, APP_SECRET)
12
+ handler.should be_true
13
+ end
14
+
15
+ it "can't be initialized without an app ID and secret" do
16
+ expect { StreetCred::Handler.new }.to raise_error
17
+ end
18
+
19
+ it "should handle the params for info request, and respond with a hash to populate the dialogue" do
20
+ # example parmas for info request, and expected response
21
+ params = {
22
+ :signed_request => SIGNED_REQUEST,
23
+ :order_status => 'tag'
24
+ }
25
+ product_info = {
26
+ 'method' => 'pay',
27
+ 'title' => 'My Awsome Virtual Item',
28
+ 'description' => 'Best. Virtual Item. Ever.',
29
+ 'image_url' => "http://2.bp.blogspot.com/-nqAn1B4aRxo/TxNmL93PoAI/AAAAAAAACvU/t0N5_6r7ds8/s1600/pid1534-dog_bowl_hi_res.jpg",
30
+ 'product_url' => 'google.com/dogs',
31
+ 'price' => 1,
32
+ 'item_id' => 'MY_ITEM_ID'
33
+ }
34
+ expected_response = {
35
+ 'content' => [product_info],
36
+ 'method' => 'payments_get_items'
37
+ }
38
+
39
+ # handle the sample params, and compare response to expected_response
40
+ handler = StreetCred::Handler.new(APP_ID, APP_SECRET)
41
+ actual_response = handler.handle(params)
42
+ actual_response.should eq(expected_response)
43
+ end
44
+
45
+ it "should handle the params for to settle an order, and respond as expected" do
46
+ # example parmas for info request, and expected response
47
+ params = {
48
+ :signed_request => SIGNED_REQUEST,
49
+ :order_details => '1234'
50
+ }
51
+ expected_response = {
52
+ 'method' => 'payments_status_update',
53
+ 'order_id' => '1234',
54
+ 'status' => 'settled',
55
+ }
56
+
57
+ # handle the sample params, and compare response to expected_response
58
+ handler = StreetCred::Handler.new(APP_ID, APP_SECRET)
59
+ actual_response = handler.handle(params)
60
+ actual_response.should eq(expected_response)
61
+ end
62
+
63
+ it "should raise an error if you handle params that doesn't contain a valid signed_request" do
64
+ params = {}
65
+ handler = StreetCred::Handler.new(APP_ID, APP_SECRET)
66
+ expect { handler.handle(params) }.to raise_error(ArgumentError, 'unable to validate signed_request')
67
+ end
68
+
69
+ end
data/streetcred.gemspec CHANGED
@@ -13,5 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "streetcred"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = Streetcred::VERSION
16
+ gem.version = StreetCred::VERSION
17
+
18
+ gem.add_runtime_dependency('koala')
19
+ gem.add_development_dependency('rspec')
17
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streetcred
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-22 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: koala
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  description: Streetcred helps to handle the credit callback needed to use Facebook
15
47
  credit.
16
48
  email:
@@ -26,8 +58,9 @@ files:
26
58
  - lib/streetcred.rb
27
59
  - lib/streetcred/version.rb
28
60
  - readme.md
61
+ - spec/spec_helper.rb
62
+ - spec/streetcred_spec.rb
29
63
  - streetcred.gemspec
30
- - streetcred_spec.rb
31
64
  homepage: https://github.com/ragingsquirrel3/streetcred
32
65
  licenses: []
33
66
  post_install_message:
@@ -48,8 +81,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
81
  version: '0'
49
82
  requirements: []
50
83
  rubyforge_project:
51
- rubygems_version: 1.8.23
84
+ rubygems_version: 1.8.24
52
85
  signing_key:
53
86
  specification_version: 3
54
87
  summary: Streetcred helps to handle the credit callback needed to use Facebook credit.
55
- test_files: []
88
+ test_files:
89
+ - spec/spec_helper.rb
90
+ - spec/streetcred_spec.rb
data/streetcred_spec.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'streetcred'
2
-
3
- describe StreetCred do
4
-
5
- it "should be able to be initialized" do
6
- credit_handler = StreetCred::HANDLER.new
7
- end
8
-
9
- it "should generate a status ticket that is a hash" do
10
- credit_handler = StreetCred::HANDLER.new
11
- credit_handler.generate_status_ticket.class.should be Hash
12
- end
13
- end
14
-