social_rebate 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/social_rebate.rb CHANGED
@@ -2,5 +2,47 @@ require "social_rebate/version"
2
2
  require "httparty"
3
3
  require "json"
4
4
  require "uri"
5
-
5
+ require "social_rebate/config"
6
6
  require "social_rebate/connection"
7
+
8
+ module SocialRebate
9
+
10
+ def self.verify(token, option={})
11
+ return unless is_enabled?
12
+ option[:status] ||= 'VERIFIED'
13
+ SocialRebate::Connection.new(creds).put("#{sub_base_uri}#{token}/", option)
14
+ end
15
+
16
+ def self.cancel(token, option={})
17
+ return unless is_enabled?
18
+ option[:status] ||= 'VOID'
19
+ SocialRebate::Connection.new(creds).put("#{sub_base_uri}#{token}", option)
20
+ end
21
+
22
+ def self.init(option={})
23
+ return unless is_enabled?
24
+ SocialRebate::Connection.new(creds).post(sub_base_uri, option)
25
+ end
26
+
27
+ def self.get(option={}, url='/api/v2/orders/')
28
+ return unless is_enabled?
29
+ SocialRebate::Connection.new(creds).get(url)
30
+ end
31
+
32
+ def self.creds
33
+ creds = {}
34
+ creds[:api_key] ||= Config.api_key
35
+ creds[:api_secret] ||= Config.api_secret
36
+ creds[:store_key] ||= Config.store_key
37
+ creds
38
+ end
39
+
40
+ def self.sub_base_uri
41
+ "/api/#{Config.api_version}/orders/"
42
+ end
43
+
44
+ def self.is_enabled?
45
+ Config.enabled?
46
+ end
47
+
48
+ end
@@ -0,0 +1,57 @@
1
+ module SocialRebate
2
+
3
+ class Config
4
+
5
+ @@api_key = @@api_secret = @@store_key = nil
6
+ @@enabled = true
7
+ @@api_version = 'v2'
8
+
9
+ class << self
10
+ def api_key=(key)
11
+ @@api_key = key
12
+ end
13
+
14
+ def api_secret=(secret)
15
+ @@api_secret = secret
16
+ end
17
+
18
+ def store_key=(store_key)
19
+ @@store_key = store_key
20
+ end
21
+
22
+ def api_version=(api_version)
23
+ @@api_version = api_version || 'v2'
24
+ end
25
+
26
+ def enabled=(enabled=true)
27
+ @@enabled = enabled
28
+ end
29
+
30
+ def api_key
31
+ @@api_key || ENV['SR_API_KEY']
32
+ end
33
+
34
+ def api_secret
35
+ @@api_secret || ENV['SR_API_SECRET']
36
+ end
37
+
38
+ def store_key
39
+ @@store_key || ENV['SR_STORE_KEY']
40
+ end
41
+
42
+ def api_version
43
+ @@api_version
44
+ end
45
+
46
+ def enabled?
47
+ @@enabled
48
+ end
49
+
50
+ def api_version
51
+ @@api_version
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -1,3 +1,3 @@
1
1
  module SocialRebate
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe SocialRebate do
4
+ before :each do
5
+ @creds = {}
6
+ @creds[:api_key] = SocialRebate::Config.api_key
7
+ @creds[:api_secret] = SocialRebate::Config.api_secret
8
+ @creds[:store_key] = SocialRebate::Config.store_key
9
+ @cn = SocialRebate::Connection.new(@creds)
10
+ SocialRebate::Connection.stub(:new).with(@creds).and_return(@cn)
11
+ @token = 'token'
12
+ @option = {:order_email => 'email', :total_purchase => '10', :order_id => 1000}
13
+ end
14
+
15
+ describe "verify" do
16
+ it "should receive correct params for put request" do
17
+ @option[:status] = "VERIFIED"
18
+ @cn.stub(:put).with("/api/v2/orders/#{@token}/", @option)
19
+ SocialRebate.verify(@token, @option)
20
+ end
21
+ end
22
+
23
+ describe "cancel" do
24
+ it "should receive correct params for cancel request" do
25
+ @option[:status] = "VOID"
26
+ @cn.stub(:put).with("/api/v2/orders/#{@token}/", @option)
27
+ SocialRebate.verify(@token, @option)
28
+ end
29
+ end
30
+
31
+ describe "init" do
32
+ it "should receive correct params for social rebate request" do
33
+ @cn.stub(:post).with("/api/v2/orders/", @option)
34
+ SocialRebate.init(@option)
35
+ end
36
+ end
37
+
38
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'httparty'
2
2
  require 'json'
3
3
  Dir[File.dirname(__FILE__)+'/../lib/social_rebate/*.rb'].each{|file| require file}
4
+ require_relative '../lib/social_rebate.rb'
4
5
 
5
6
  RSpec.configure do |config|
6
7
  config.treat_symbols_as_metadata_keys_with_true_values = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_rebate
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,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-25 00:00:00.000000000 Z
12
+ date: 2013-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -122,10 +122,12 @@ files:
122
122
  - README.md
123
123
  - Rakefile
124
124
  - lib/social_rebate.rb
125
+ - lib/social_rebate/config.rb
125
126
  - lib/social_rebate/connection.rb
126
127
  - lib/social_rebate/version.rb
127
128
  - social_rebate.gemspec
128
129
  - spec/connection_spec.rb
130
+ - spec/social_rebate_spec.rb
129
131
  - spec/spec_helper.rb
130
132
  homepage: https://github.com/daifu/social_rebate_api_wrapper
131
133
  licenses:
@@ -154,4 +156,5 @@ specification_version: 3
154
156
  summary: Social Rebate
155
157
  test_files:
156
158
  - spec/connection_spec.rb
159
+ - spec/social_rebate_spec.rb
157
160
  - spec/spec_helper.rb