share_a_sale 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78ae24b6850a6550f1364109bd41f3575172aee4
4
+ data.tar.gz: 59c94670d5d4233f169eb284a29f58c2ddec13f6
5
+ SHA512:
6
+ metadata.gz: f21e6012289a8bd2bfb0fed2412dd82c5b20cb993adbfd4da821c1955f8e1cfc2ebe877d078c285913734e31c298b6960c85b3bd877cd3c017b25503d05e1d4a
7
+ data.tar.gz: 4c5bcce1ab52573ba0a5759bdee4cc1fc8201a44ad718dc7224ab2446eb80fb2dfbdc7f92367add910eaaf72661b90e730587b78686a1a4260e95a04505de60a
@@ -1,54 +1,18 @@
1
- require "share_a_sale/version"
2
1
  require 'digest'
3
2
  require 'uri'
4
3
  require 'rest-client'
5
4
 
6
- module ShareASale
7
- SHARE_A_SALE_HOST = "shareasale.com"
8
- SHARE_A_SALE_PATH = "/w.cfm"
9
- SHARE_A_SALE_VERSION = "1.8"
10
-
11
- class Client < Struct.new(:merchant_id, :token, :api_secret)
12
- { banner_list: "bannerList", transaction_detail: "transactionDetail", reference: "reference" }.each do |method, api_action|
13
- class_eval <<-EORUBY, __FILE__, __LINE__
14
- def #{method}(options = {}, date = Time.now)
15
- request('#{api_action}', options, date).execute!
16
- end
17
- EORUBY
18
- end
19
-
20
- def request(action, options, date = Time.now)
21
- Request.new(merchant_id, token, api_secret, action, options, date)
22
- end
23
- end
24
-
25
- class Request < Struct.new(:merchant_id, :token, :api_secret, :action, :options, :date)
26
- def date_string
27
- date.strftime("%a, %d %b %Y %H:%M:%S GMT")
28
- end
5
+ require 'share_a_sale/version'
6
+ require 'share_a_sale/request'
7
+ require 'share_a_sale/client'
29
8
 
30
- def string_to_hash
31
- "#{token}:#{date_string}:#{action}:#{api_secret}"
32
- end
33
9
 
34
- def authentication_hash
35
- Digest::SHA256.hexdigest(string_to_hash).upcase
36
- end
37
-
38
- def url
39
- params = [['merchantId', merchant_id], ['token', token], ['version', SHARE_A_SALE_VERSION], ['action', action], ['date', date.strftime("%D")]] + options.to_a
40
- URI::HTTPS.build(host: SHARE_A_SALE_HOST, path: SHARE_A_SALE_PATH, query: URI.encode_www_form(params)).to_s
41
- end
42
-
43
- def custom_headers
44
- {
45
- "x-ShareASale-Date" => date_string,
46
- "x-ShareASale-Authentication" => authentication_hash
47
- }
48
- end
49
-
50
- def execute!
51
- RestClient.get(url, custom_headers)
52
- end
10
+ module ShareASale
11
+ def self.client
12
+ @client ||= ShareASale::Client.new(
13
+ ENV.fetch('SHAREASALE_MERCH_ID'),
14
+ ENV.fetch('SHAREASALE_API_TOKEN'),
15
+ ENV.fetch('SHAREASALE_API_SECRET')
16
+ )
53
17
  end
54
18
  end
@@ -0,0 +1,17 @@
1
+ module ShareASale
2
+ class Client < Struct.new(:merchant_id, :token, :api_secret)
3
+
4
+ { banner_list: "bannerList", transaction_detail: "transactionDetail", reference: "reference" }.each do |method, api_action|
5
+ class_eval <<-EORUBY, __FILE__, __LINE__
6
+ def #{method}(options = {}, date = Time.now.utc)
7
+ request('#{api_action}', options, date).execute!
8
+ end
9
+ EORUBY
10
+ end
11
+
12
+ def request(action, options, date = Time.now.utc)
13
+ Request.new(merchant_id, token, api_secret, action, options, date)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,57 @@
1
+ module ShareASale
2
+ class Request < Struct.new(:merchant_id, :token, :api_secret, :action, :options, :date)
3
+
4
+ def date_string
5
+ date.strftime("%a, %d %b %Y %H:%M:%S GMT")
6
+ end
7
+
8
+ def string_to_hash
9
+ "#{token}:#{date_string}:#{action}:#{api_secret}"
10
+ end
11
+
12
+ def authentication_hash
13
+ Digest::SHA256.hexdigest(string_to_hash).upcase
14
+ end
15
+
16
+ def url
17
+ params = [
18
+ ['merchantId', merchant_id],
19
+ ['token', token],
20
+ ['version', version],
21
+ ['action', action],
22
+ ['date', date.strftime("%D")]
23
+ ] + options.to_a
24
+
25
+ URI::HTTPS.build(
26
+ host: host,
27
+ path: path,
28
+ query: params.map{|p| p.join('=') }.join('&')
29
+ ).to_s
30
+ end
31
+
32
+ def custom_headers
33
+ {
34
+ "x-ShareASale-Date" => date_string,
35
+ "x-ShareASale-Authentication" => authentication_hash
36
+ }
37
+ end
38
+
39
+ def execute!
40
+ RestClient.get(url, custom_headers)
41
+ end
42
+
43
+ protected
44
+
45
+ def host
46
+ ENV.fetch('SHAREASALE_HOST', 'api.shareasale.com')
47
+ end
48
+
49
+ def path
50
+ ENV.fetch('SHAREASALE_PATH', '/w.cfm')
51
+ end
52
+
53
+ def version
54
+ ENV.fetch('SHAREASALE_VERSION', '2.8')
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module ShareASale
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'rest-client'
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rspec", "3.6.0"
25
25
  end
@@ -0,0 +1,7 @@
1
+ require 'share_a_sale'
2
+
3
+ describe ShareASale::Client do
4
+
5
+ pending 'Add tests 😭'
6
+
7
+ end
@@ -0,0 +1,45 @@
1
+ require 'share_a_sale'
2
+
3
+ describe ShareASale::Request do
4
+ context "API metadata" do
5
+
6
+ let(:client) do
7
+ ShareASale::Client.new(
8
+ 1234,
9
+ 'NGc6dg5e9URups5o',
10
+ 'ATj7vd8b7CCjeq9yQUo8cc2w3OThqe2e'
11
+ )
12
+ end
13
+
14
+ subject do
15
+ client.request(
16
+ 'bannerList',
17
+ { param: 'value' },
18
+ Time.gm(2011, 04, 14, 22, 44, 22)
19
+ )
20
+ end
21
+
22
+ specify do
23
+ expect(subject.date_string).to eq("Thu, 14 Apr 2011 22:44:22 GMT")
24
+ end
25
+
26
+ specify do
27
+ expect(subject.string_to_hash).to eq(
28
+ "NGc6dg5e9URups5o:Thu, 14 Apr 2011 22:44:22 GMT:bannerList:ATj7vd8b7CCjeq9yQUo8cc2w3OThqe2e"
29
+ )
30
+ end
31
+
32
+ specify do
33
+ expect(subject.authentication_hash).to eq(
34
+ "78D54A3051AE0AAAF022AA2DA230B97D5219D82183FEFF71E2D53DEC6057D9F1"
35
+ )
36
+ end
37
+
38
+ specify do
39
+ expect(subject.url).to eq(
40
+ "https://api.shareasale.com/w.cfm?merchantId=1234&token=NGc6dg5e9URups5o&version=2.8&action=bannerList&date=04/14/11&param=value"
41
+ )
42
+ end
43
+
44
+ end
45
+ end
@@ -1,15 +1,23 @@
1
1
  require 'share_a_sale'
2
2
 
3
- module ShareASale
4
- describe Request do
5
- context "API metadata" do
6
- let(:client) { Client.new(1234, 'NGc6dg5e9URups5o', 'ATj7vd8b7CCjeq9yQUo8cc2w3OThqe2e') }
7
- subject { client.request('bannerList', { param: 'value' }, Time.gm(2011, 04, 14, 22, 44, 22)) }
8
-
9
- its(:date_string) { should eq "Thu, 14 Apr 2011 22:44:22 GMT" }
10
- its(:string_to_hash) { should eq "NGc6dg5e9URups5o:Thu, 14 Apr 2011 22:44:22 GMT:bannerList:ATj7vd8b7CCjeq9yQUo8cc2w3OThqe2e" }
11
- its(:authentication_hash) { should eq "78D54A3051AE0AAAF022AA2DA230B97D5219D82183FEFF71E2D53DEC6057D9F1" }
12
- its(:url) { should eq "https://shareasale.com/w.cfm?merchantId=1234&token=NGc6dg5e9URups5o&version=1.8&action=bannerList&date=04/14/11&param=value"}
3
+ describe ShareASale do
4
+
5
+ describe '.client' do
6
+ context 'without credentials in ENV' do
7
+ it 'raises an error' do
8
+ expect { ShareASale.client }.to raise_error(KeyError)
9
+ end
10
+ end
11
+
12
+ context 'with credentials in ENV' do
13
+ it 'returns an instance of ShareASale::Client' do
14
+ ENV['SHAREASALE_MERCH_ID'] = '123'
15
+ ENV['SHAREASALE_API_TOKEN'] = 'foo'
16
+ ENV['SHAREASALE_API_SECRET'] = 'bar'
17
+
18
+ expect(ShareASale.client).to be_instance_of(ShareASale::Client)
19
+ end
13
20
  end
14
21
  end
22
+
15
23
  end
metadata CHANGED
@@ -1,80 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: share_a_sale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tejas Dinkar
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rest-client
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '1.3'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '='
68
60
  - !ruby/object:Gem::Version
69
- version: '0'
61
+ version: 3.6.0
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '='
76
67
  - !ruby/object:Gem::Version
77
- version: '0'
68
+ version: 3.6.0
78
69
  description: Gem to share sales via the Share a Sale Network
79
70
  email:
80
71
  - tejas@gja.in
@@ -82,49 +73,44 @@ executables: []
82
73
  extensions: []
83
74
  extra_rdoc_files: []
84
75
  files:
85
- - !binary |-
86
- LmdpdGlnbm9yZQ==
87
- - !binary |-
88
- R2VtZmlsZQ==
89
- - !binary |-
90
- TElDRU5TRS50eHQ=
91
- - !binary |-
92
- UkVBRE1FLm1k
93
- - !binary |-
94
- UmFrZWZpbGU=
95
- - !binary |-
96
- bGliL3NoYXJlX2Ffc2FsZS5yYg==
97
- - !binary |-
98
- bGliL3NoYXJlX2Ffc2FsZS92ZXJzaW9uLnJi
99
- - !binary |-
100
- c2hhcmVfYV9zYWxlLmdlbXNwZWM=
101
- - !binary |-
102
- c3BlYy9zaGFyZV9hX3NhbGVfc3BlYy5yYg==
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/share_a_sale.rb
82
+ - lib/share_a_sale/client.rb
83
+ - lib/share_a_sale/request.rb
84
+ - lib/share_a_sale/version.rb
85
+ - share_a_sale.gemspec
86
+ - spec/share_a_sale/client_spec.rb
87
+ - spec/share_a_sale/request_spec.rb
88
+ - spec/share_a_sale_spec.rb
103
89
  homepage: ''
104
90
  licenses:
105
91
  - MIT
92
+ metadata: {}
106
93
  post_install_message:
107
94
  rdoc_options: []
108
95
  require_paths:
109
96
  - lib
110
97
  required_ruby_version: !ruby/object:Gem::Requirement
111
- none: false
112
98
  requirements:
113
- - - ! '>='
99
+ - - ">="
114
100
  - !ruby/object:Gem::Version
115
101
  version: '0'
116
102
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
103
  requirements:
119
- - - ! '>='
104
+ - - ">="
120
105
  - !ruby/object:Gem::Version
121
106
  version: '0'
122
107
  requirements: []
123
108
  rubyforge_project:
124
- rubygems_version: 1.8.23
109
+ rubygems_version: 2.5.1
125
110
  signing_key:
126
- specification_version: 3
111
+ specification_version: 4
127
112
  summary: Gem to share sales via the Share a Sale Network
128
113
  test_files:
129
- - !binary |-
130
- c3BlYy9zaGFyZV9hX3NhbGVfc3BlYy5yYg==
114
+ - spec/share_a_sale/client_spec.rb
115
+ - spec/share_a_sale/request_spec.rb
116
+ - spec/share_a_sale_spec.rb