referral_candy 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ReferralCandy
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,46 @@
1
+ # ReferralCandy Ruby API Client
2
+
3
+ ## Installation
4
+
5
+ gem install 'referral_candy'
6
+
7
+ ## Usage
8
+
9
+ ### Initialization
10
+
11
+ Initialize a client with your ReferralCandy credentials
12
+
13
+ rc = ReferralCandy.new(:access_id => "YOUR_ACCESS_ID", :secret_key => "YOUR_SECRET_KEY")
14
+
15
+ ### Verification
16
+
17
+ Verify your credentials.
18
+
19
+ response = rc.verify
20
+ response.parsed_response # => {"message"=>"Verification Ok"}
21
+ response.code # => 200
22
+
23
+ ### API Methods
24
+
25
+ The ReferralCandy API client will perform the [authentication](http://www.referralcandy.com/api#authentication) steps for you.
26
+ This means that you would not be required to pass in the 'timestamp', 'accessID', and 'signature' parameters.
27
+
28
+ [API endpoints](http://www.referralcandy.com/api) are available as methods in the ReferralCandy API client.
29
+
30
+ E.g.
31
+
32
+ rc.contacts(:limit => 1).parsed_response
33
+ # => {"message"=>"Success", "total_count"=>10000, "contacts"=>[{"id"=>1, "first_name"=>"Yink", "last_name"=>"Teo", "email"=>"hello@referralcandy.com", "purchase_made"=>false, "purchases"=>[], "unsubscribed"=>true}]}
34
+
35
+ ### Responses
36
+
37
+ The ReferralCandy API client uses [HTTParty](https://github.com/jnunemaker/httparty).
38
+
39
+ rc.verify.class # => HTTParty::Response
40
+ rc.verify.body # => "{\"message\":\"Verification Ok\"}"
41
+ rc.verify.parsed_response # => {"message"=>"Verification Ok"}
42
+ rc.verify.code # => 200
43
+ rc.verify.header # => #<Net::HTTPOK 200 OK readbody=true>
44
+
45
+ ## Documentation
46
+ [API documentation](http://www.referralcandy.com/api)
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
@@ -0,0 +1,56 @@
1
+ require 'digest/md5'
2
+ require 'httparty'
3
+
4
+ class ReferralCandy
5
+ DEFAULT_API_URL = "https://my.referralcandy.com/api/v1/"
6
+ API_METHODS = {
7
+ get: [:verify, :referrals, :referrer, :contacts],
8
+ post: [:purchase, :referral, :signup, :invite]
9
+ }
10
+
11
+ include HTTParty
12
+ base_uri DEFAULT_API_URL
13
+ format :json
14
+
15
+ attr_reader :secret_key, :access_id
16
+ class << self
17
+ def api_url= url
18
+ base_uri url
19
+ @api_url = url
20
+ end
21
+ def api_url
22
+ @api_url || DEFAULT_API_URL
23
+ end
24
+ end
25
+
26
+ def initialize(options = {})
27
+ @access_id = options[:access_id]
28
+ @secret_key = options[:secret_key]
29
+ end
30
+
31
+ API_METHODS.each do |verb, end_points|
32
+ end_points.each do |ep|
33
+ class_eval <<-EVAL
34
+ def #{ep}(params = {})
35
+ ReferralCandy.#{verb}("/#{ep}.json", query: add_signature_to(params))
36
+ end
37
+ EVAL
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def add_signature_to input_params
44
+ params = input_params.merge({
45
+ :accessID => self.access_id,
46
+ :timestamp => Time.now.to_i
47
+ })
48
+ params[:signature] = signature(params)
49
+ params
50
+ end
51
+
52
+ def signature params = {}
53
+ collected_params = params.map{|k, v| "#{k}=#{v}"}.sort.join
54
+ Digest::MD5.hexdigest(self.secret_key + collected_params)
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ class ReferralCandy
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/referral_candy/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'referral_candy'
6
+ s.version = ReferralCandy::VERSION.dup
7
+ s.date = '2011-12-12'
8
+ s.summary = "ReferralCandy Ruby API Client"
9
+ s.description = "Ruby wrapper for ReferralCandy API"
10
+ s.authors = ["Yinquan Teo", "Sean Xie Sheng Xiang", "Dinesh Raju"]
11
+ s.email = 'hello@referralcandy.com'
12
+ s.homepage = 'http://www.referralcandy.com/api'
13
+
14
+ s.files = `git ls-files`.split($\)
15
+ s.test_files = s.files.grep(%r{^(spec)/})
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_dependency "httparty", ">= 0.8.0"
19
+ s.add_development_dependency "rspec", "~> 2.9.0"
20
+
21
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ describe ReferralCandy do
5
+
6
+ let(:secret_key) { 'access_token' }
7
+ let(:access_id) { 'access_id' }
8
+ let(:refcandy) { ReferralCandy.new(access_id: access_id, secret_key: secret_key) }
9
+ let(:params) { {:name => "john"} }
10
+ let(:pre_signed_params) { params.merge(:accessID => access_id, :timestamp => 1) }
11
+
12
+ describe ".initialize" do
13
+ subject { refcandy }
14
+ its(:secret_key) { should == secret_key }
15
+ its(:access_id) { should == access_id }
16
+ end
17
+
18
+ describe "#api_url" do
19
+ subject { ReferralCandy }
20
+ its(:api_url) { should == ReferralCandy::DEFAULT_API_URL }
21
+ end
22
+
23
+ describe ".add_signature_to" do
24
+ it "should add accessID to params" do
25
+ refcandy.send(:add_signature_to, params)[:accessID].should == access_id
26
+ end
27
+ it "should add timestamp to params" do
28
+ Time.stub(:now).and_return(1)
29
+ refcandy.send(:add_signature_to, params)[:timestamp].should == 1
30
+ end
31
+ it "should add signature to params" do
32
+ Time.stub(:now).and_return(1)
33
+ refcandy.send(:add_signature_to, params)[:signature].should == refcandy.send(:signature, pre_signed_params)
34
+ end
35
+ end
36
+ describe ".signature" do
37
+ it "should calculate the correct signature" do
38
+ refcandy.send(:signature, pre_signed_params).should == '25cb1ed0c5e9e64f09fa4db9ed7ff156'
39
+ end
40
+ end
41
+
42
+ describe ".verify" do
43
+ it "should GET verify.json with correct params" do
44
+ ReferralCandy.should_receive(:get).once.with("/verify.json", :query => refcandy.send(:add_signature_to, {}))
45
+ refcandy.verify
46
+ end
47
+ end
48
+
49
+ describe ".purchase" do
50
+ let(:purchase_params) {{
51
+ :first_name => "John",
52
+ :last_name => "Doe",
53
+ :email => "john@doe.com",
54
+ :order_timestamp => Time.now.to_i,
55
+ :browser_ip => "123.123.123.123",
56
+ :user_agent => "I like iOS",
57
+ :invoice_amount => 500,
58
+ }}
59
+ it "should POST purchase.json with correct params" do
60
+ ReferralCandy.should_receive(:post).once.with("/purchase.json", :query => refcandy.send(:add_signature_to, purchase_params))
61
+ refcandy.purchase(purchase_params)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'referral_candy')
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: referral_candy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yinquan Teo
9
+ - Sean Xie Sheng Xiang
10
+ - Dinesh Raju
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-12-12 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 0.8.0
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 2.9.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.9.0
48
+ description: Ruby wrapper for ReferralCandy API
49
+ email: hello@referralcandy.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/referral_candy.rb
60
+ - lib/referral_candy/version.rb
61
+ - referral_candy.gemspec
62
+ - spec/referral_candy_spec.rb
63
+ - spec/spec_helper.rb
64
+ homepage: http://www.referralcandy.com/api
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: ReferralCandy Ruby API Client
88
+ test_files:
89
+ - spec/referral_candy_spec.rb
90
+ - spec/spec_helper.rb