adyen-admin 0.0.2 → 0.0.3

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.
Files changed (24) hide show
  1. data/CHANGES.md +10 -4
  2. data/README.md +1 -1
  3. data/VERSION +1 -1
  4. data/lib/adyen-admin.rb +3 -0
  5. data/lib/adyen-admin/client.rb +11 -0
  6. data/lib/adyen-admin/skin.rb +57 -32
  7. data/spec/adyen-admin/client_spec.rb +12 -0
  8. data/spec/adyen-admin/skin_spec.rb +137 -112
  9. data/spec/fixtures/cassettes/Adyen_Admin_Client/_get/raises_authenticated_error_when_not_logged_in.yml +271 -0
  10. data/spec/fixtures/cassettes/Adyen_Admin_Client/_login/passes_with_correct_username_password.yml +35 -35
  11. data/spec/fixtures/cassettes/Adyen_Admin_Skin/authenticated/_all/freezes_local_skins.yml +292 -0
  12. data/spec/fixtures/cassettes/Adyen_Admin_Skin/{_all → authenticated/_all}/returns_the_skins.yml +27 -4
  13. data/spec/fixtures/cassettes/Adyen_Admin_Skin/authenticated/_all_remote/returns_the_skins.yml +292 -0
  14. data/spec/fixtures/cassettes/Adyen_Admin_Skin/{_download → authenticated/_download}/gets_the_file.yml +7 -7
  15. data/spec/fixtures/cassettes/Adyen_Admin_Skin/authenticated/_find/returns_no_skin.yml +292 -0
  16. data/spec/fixtures/cassettes/Adyen_Admin_Skin/authenticated/_find/returns_the_skin.yml +292 -0
  17. data/spec/fixtures/cassettes/Adyen_Admin_Skin/{_test_url → authenticated/_test_url}/returns_url_to_test.yml +17 -17
  18. data/spec/fixtures/cassettes/Adyen_Admin_Skin/{_upload → authenticated/_upload}/valid_set/increases_version.yml +119 -96
  19. data/spec/fixtures/cassettes/Adyen_Admin_Skin/{_version → authenticated/_version}/returns_live_value.yml +4 -4
  20. data/spec/fixtures/cassettes/Adyen_Admin_Skin/{_version → authenticated/_version}/returns_test_value.yml +5 -5
  21. data/spec/fixtures/cassettes/Adyen_Admin_Skin/{_version → authenticated/_version}/returns_uploaded_value.yml +8 -8
  22. data/spec/fixtures/cassettes/login.yml +38 -45
  23. data/spec/spec_helper.rb +1 -0
  24. metadata +40 -30
data/CHANGES.md CHANGED
@@ -2,12 +2,18 @@
2
2
 
3
3
  ## vx.x.x - ???
4
4
  * update Docu
5
- * metafile
6
- * parent
7
- * build binaries
5
+ * parse metafile
6
+ * parent (instead of base)
7
+ * add CLI binaries (to compile + upload) -> read from .adyenrc file
8
8
  * make compatible with Live system
9
9
 
10
- ## v0.0.2 - ???
10
+ ## v0.0.2
11
+ * force update remote
12
+ * .all unions remote + local (no more duplicates)
13
+ * freeze locals to indicate missing remote endpoint
14
+ * raise exception when page could not be loaded
15
+
16
+ ## v0.0.2
11
17
  * cleanup
12
18
  * dep. fix
13
19
 
data/README.md CHANGED
@@ -21,7 +21,7 @@ require 'adyen/admin'
21
21
 
22
22
  Adyen::Admin.login(<accountname>, <username>, <password>)
23
23
 
24
- Adyen::Admin::Skin.all #returns all remote skins
24
+ Adyen::Admin::Skin.all #returns all remote + local skins
25
25
 
26
26
  ```
27
27
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/adyen-admin.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # Copyright (c) 2012, SoundCloud Ltd., Tobias Bielohlawek
2
+
2
3
  require 'adyen-admin/client'
3
4
  require 'adyen-admin/skin'
4
5
 
@@ -6,6 +7,8 @@ module Adyen
6
7
  module Admin
7
8
  extend Adyen::Admin::Client
8
9
 
10
+ class AuthenticationError < StandardError; end
11
+
9
12
  def skin_dir
10
13
  "."
11
14
  end
@@ -7,6 +7,7 @@ module Adyen
7
7
  DASHBOARD = "https://ca-test.adyen.com/ca/ca/overview/default.shtml"
8
8
 
9
9
  def login(accountname, username, password)
10
+ @authenticated = false
10
11
  page = Adyen::Admin.client.get(LOGIN)
11
12
  page = Adyen::Admin.client.submit(page.form.tap do |form|
12
13
  form.j_account = accountname
@@ -14,12 +15,22 @@ module Adyen
14
15
  form.j_password = password
15
16
  end)
16
17
  raise "Wrong username + password combination" if page.uri.to_s != DASHBOARD
18
+ @authenticated = true
19
+ end
20
+
21
+ def get(url)
22
+ client.get(url).tap do |page|
23
+ raise AuthenticationError unless page.uri.to_s.include?(url)
24
+ end
17
25
  end
18
26
 
19
27
  def client
20
28
  @agent ||= Mechanize.new
21
29
  end
22
30
 
31
+ def authenticated?
32
+ @authenticated
33
+ end
23
34
  end
24
35
  end
25
36
  end
@@ -13,27 +13,35 @@ module Adyen
13
13
  PUBLISH = "https://ca-test.adyen.com/ca/ca/skin/publishskin.shtml?skinCode=%s"
14
14
  SKINS = "https://ca-test.adyen.com/ca/ca/skin/skins.shtml"
15
15
 
16
- attr_accessor :code, :name, :path
16
+ attr_reader :code, :name, :path
17
17
 
18
18
  def initialize(attributes = {})
19
19
  attributes.each do |key, value|
20
20
  send("#{key}=", value)
21
21
  end
22
22
 
23
- if !path && code
24
- path = skin_path([code,name].join("-"))
25
- end
23
+ path ||= File.join(Adyen::Admin.skin_dir, [code,name].compact.join("-"))
26
24
 
27
25
  raise ArgumentError unless code
28
26
  end
29
27
 
28
+ # union remote and local skins. Local skins are frozen to
29
+ # indicate no availble remote counter part which avoid update
30
30
  def self.all(path = nil)
31
- all_remote + all_local(path)
31
+ {}.tap do |hash|
32
+ self.all_remote.each do |skin|
33
+ hash[skin.code] = skin unless hash[skin.code]
34
+ end
35
+ self.all_local(path).each do |skin|
36
+ hash[skin.code] = skin.freeze unless hash[skin.code]
37
+ end
38
+ end.values
32
39
  end
33
40
 
41
+ # fetch all remote skins
34
42
  def self.all_remote
35
43
  @@skins_remote ||= begin
36
- page = Adyen::Admin.client.get(SKINS)
44
+ page = Adyen::Admin.get(SKINS)
37
45
  page.search(".data tbody tr").map do |node|
38
46
  Skin.new({
39
47
  :code => node.search("a")[0].content.strip,
@@ -43,45 +51,54 @@ module Adyen
43
51
  end
44
52
  end
45
53
 
54
+ # fetch all local skins
46
55
  def self.all_local(path)
47
56
  Dir[File.join(path.to_s, "*")].map do |path|
48
57
  Skin.new(:path => path) rescue nil
49
58
  end.compact
50
59
  end
51
60
 
61
+ # find a skin within remote + local ones
52
62
  def self.find(skin_code)
53
- all.select do |skin|
63
+ self.all.select do |skin|
54
64
  skin.code == skin_code
55
65
  end.first
56
66
  end
57
67
 
68
+ def self.purge_cache
69
+ @@skins_remote = nil
70
+ end
71
+
58
72
  ##################################
73
+
59
74
  def path=(path)
60
75
  if Skin.is_skin_path?(path)
61
- code, name = File.basename(path).split("-").reverse
62
- self.code ||= code
63
- self.name ||= name
64
- raise ArgumentError if code && self.code != code
76
+ new_code, new_name = File.basename(path).split("-").reverse
77
+ self.code ||= new_code
78
+ self.name ||= new_name
79
+ raise ArgumentError if self.code && self.code != new_code
65
80
  @path = path
66
81
  end
67
82
  end
68
83
 
84
+ ##################################
85
+
69
86
  def version(scope = :local)
70
87
  case scope
71
88
  when :test
72
- page = Adyen::Admin.client.get(VERSION_TEST % code)
89
+ page = Adyen::Admin.get(VERSION_TEST % code)
73
90
  page.search("body p").first.content.scan(/Version:(\d+)/).flatten.first.to_i
74
91
  when :live
75
- page = Adyen::Admin.client.get(VERSION_LIVE % code)
92
+ page = Adyen::Admin.get(VERSION_LIVE % code)
76
93
  page.search("body p").first.content.scan(/Version:(\d+)/).flatten.first.to_i
77
94
  else
78
- page = Adyen::Admin.client.get(TEST % code)
95
+ page = Adyen::Admin.get(TEST % code)
79
96
  page.search(".data tr td")[2].content.to_i
80
97
  end
81
98
  end
82
99
 
83
100
  def test_url(options = {})
84
- page = Adyen::Admin.client.get(TEST % code)
101
+ page = Adyen::Admin.get(TEST % code)
85
102
  page = Adyen::Admin.client.submit(page.form.tap do |form|
86
103
  #:amount => 199, :currency => :shopper_locale, :country_code, :merchant_reference, :merchant_account, :system, :skip, :one_page
87
104
  end)
@@ -120,25 +137,28 @@ module Adyen
120
137
  zipfile.add(file.sub(path, code), file)
121
138
  end
122
139
 
123
- if dir = skin_path("base")
124
- Dir["#{dir}/**/**"].each do |file|
125
- begin
126
- next if file.include?(".yml")
127
- next if file.include?(".erb")
128
- zipfile.add(file.sub(dir, code), file)
129
- rescue Zip::ZipEntryExistsError
130
- # NOOP
131
- end
140
+ dir = File.join(File.dirname(path), parent_skin_code)
141
+ Dir["#{dir}/**/**"].each do |file|
142
+ begin
143
+ next if file.include?(".yml")
144
+ next if file.include?(".erb")
145
+ zipfile.add(file.sub(dir, code), file)
146
+ rescue Zip::ZipEntryExistsError
147
+ # NOOP
132
148
  end
133
149
  end
134
150
  end
135
151
  end
136
152
  end
137
153
 
154
+ def parent_skin_code
155
+ "base"
156
+ end
157
+
138
158
  # http://stackoverflow.com/questions/3420587/ruby-mechanize-multipart-form-with-file-upload-to-a-mediawiki
139
159
  def upload
140
160
  file = self.compile
141
- page = Adyen::Admin.client.get(UPLOAD % code)
161
+ page = Adyen::Admin.get(UPLOAD % code)
142
162
  page = Adyen::Admin.client.submit(page.form.tap do |form|
143
163
  form.file_uploads.first.file_name = file
144
164
  end)
@@ -149,25 +169,30 @@ module Adyen
149
169
  def publish
150
170
  raise ArgumentError unless code
151
171
 
152
- page = Adyen::Admin.client.get(PUBLISH % code)
172
+ page = Adyen::Admin.get(PUBLISH % code)
153
173
  page = Adyen::Admin.client.submit(page.form.tap do |form|
154
174
  end)
155
175
  end
156
176
 
157
177
  #################################
158
178
 
159
- def skin_path(skin_code)
160
- skin_dir = path ? File.dirname(path) : Adyen::Admin.skin_dir
161
- File.join(skin_dir, skin_code).tap do |path|
162
- return nil unless File.directory?(path)
163
- end
179
+ def to_s
180
+ self.code
164
181
  end
165
182
 
166
183
  def ==(skin)
167
184
  self.code == skin.code
168
185
  end
169
186
 
170
- private
187
+ protected
188
+ def code=(c)
189
+ @code = c
190
+ end
191
+
192
+ def name=(n)
193
+ @name = n
194
+ end
195
+
171
196
  def self.is_skin_path?(path)
172
197
  %w(skin.html.erb inc css js).each do |sub_path|
173
198
  return true if File.exists?(File.join(path, sub_path))
@@ -5,6 +5,10 @@ require "adyen-admin/client"
5
5
  describe Adyen::Admin::Client, :vcr do
6
6
  let(:login) { Adyen::Admin.login("SoundCloud", "skinadmin", "12312311") }
7
7
 
8
+ before do
9
+ Adyen::Admin.client.cookie_jar.clear!
10
+ end
11
+
8
12
  describe "#login" do
9
13
  it 'passes with correct username + password' do
10
14
  expect do
@@ -18,4 +22,12 @@ describe Adyen::Admin::Client, :vcr do
18
22
  end
19
23
  end
20
24
  end
25
+
26
+ describe "#get" do
27
+ it 'raises authenticated error when not logged in' do
28
+ expect do
29
+ Adyen::Admin.get(Adyen::Admin::Skin::SKINS)
30
+ end.to raise_error Adyen::Admin::AuthenticationError
31
+ end
32
+ end
21
33
  end
@@ -9,166 +9,191 @@ module Adyen::Admin
9
9
  let(:skin_code) { "7hFAQnmt" }
10
10
  let(:skin) { Skin.new(:code => skin_code, :name => "example") }
11
11
 
12
- before(:all) do
13
- VCR.use_cassette("login") do
14
- Adyen::Admin.login("SoundCloud", "skinadmin", "12312311")
12
+ context "authenticated" do
13
+ before(:all) do
14
+ VCR.use_cassette("login") do
15
+ Adyen::Admin.client.cookie_jar.clear!
16
+ Adyen::Admin.login("SoundCloud", "skinadmin", "12312311")
17
+ end
15
18
  end
16
- end
17
19
 
18
- describe ".all" do
19
- it 'returns the skins' do
20
- Skin.all.should == [
21
- skin,
22
- Skin.new(:code => "Kx9axnRf", :name => "demo")
23
- ]
20
+ before do
21
+ Adyen::Admin::Skin.purge_cache
24
22
  end
25
- end
26
23
 
27
- describe ".all_local" do
28
- it 'returns the skins' do
29
- Skin.all_local(skin_fixtures).should == [
30
- Skin.new(:code => "base"),
31
- Skin.new(:code => "DV3tf95f"),
32
- skin,
33
- Skin.new(:code => "JH0815"),
34
- ]
24
+ describe ".all_remote" do
25
+ it 'returns the skins' do
26
+ Skin.all.should == [
27
+ skin,
28
+ Skin.new(:code => "Kx9axnRf", :name => "demo"),
29
+ Skin.new(:code => "vQW0fEo8", :name => "test"),
30
+ ]
31
+ end
35
32
  end
36
- end
37
33
 
38
- describe ".find" do
39
- it 'returns the skin' do
40
- Skin.find(skin_code).should == skin
34
+ describe ".all_local" do
35
+ it 'returns the skins' do
36
+ Skin.all_local(skin_fixtures).should == [
37
+ Skin.new(:code => "base"),
38
+ Skin.new(:code => "DV3tf95f"),
39
+ skin,
40
+ Skin.new(:code => "JH0815"),
41
+ ]
42
+ end
41
43
  end
42
44
 
43
- it 'returns no skin' do
44
- Skin.find("dummy code").should == nil
45
+ describe ".all" do
46
+ it 'returns the skins' do
47
+ Skin.all(skin_fixtures).should == [
48
+ skin,
49
+ Skin.new(:code => "Kx9axnRf", :name => "demo"),
50
+ Skin.new(:code => "vQW0fEo8", :name => "test"),
51
+ Skin.new(:code => "base"),
52
+ Skin.new(:code => "DV3tf95f"),
53
+ Skin.new(:code => "JH0815")
54
+ ]
55
+ end
56
+
57
+ it 'freezes local skins' do
58
+ Skin.all(skin_fixtures).last.should be_frozen
59
+ end
45
60
  end
46
- end
47
61
 
48
- describe "#new" do
49
- let(:path) { "#{skin_fixtures}/example-7hFAQnmt" }
50
62
 
51
- it "sets code attribute" do
52
- Skin.new(:code => skin_code).code.should == skin_code
53
- end
63
+ describe ".find" do
64
+ it 'returns the skin' do
65
+ Skin.find(skin_code).should == skin
66
+ end
54
67
 
55
- it "sets name attribute" do
56
- Skin.new(:code => skin_code, :name => "name").name.should == "name"
68
+ it 'returns no skin' do
69
+ Skin.find("dummy code").should == nil
70
+ end
57
71
  end
58
72
 
59
- it "sets path attribute" do
60
- Skin.new(:path => path).path.should == path
61
- end
73
+ describe "#new" do
74
+ let(:path) { "#{skin_fixtures}/example-7hFAQnmt" }
62
75
 
63
- it "auto sets code from path" do
64
- Skin.new(:path => path).code.should == "7hFAQnmt"
65
- end
76
+ it "sets code attribute" do
77
+ Skin.new(:code => skin_code).code.should == skin_code
78
+ end
66
79
 
67
- it "raises error on wrong code for path" do
68
- expect do
69
- Skin.new(:code => "different", :path => path).path.should == path
70
- end.to raise_error
71
- end
80
+ it "sets name attribute" do
81
+ Skin.new(:code => skin_code, :name => "name").name.should == "name"
82
+ end
72
83
 
73
- it "raises error on empty code" do
74
- expect do
75
- Skin.new
76
- end.to raise_error
77
- end
78
- end
84
+ it "sets path attribute" do
85
+ Skin.new(:path => path).path.should == path
86
+ end
79
87
 
80
- describe "#download" do
81
- let(:zip_filename) { "#{skin.code}.zip"}
82
- after do
83
- `rm -rf #{zip_filename}`
84
- end
88
+ it "auto sets code from path" do
89
+ Skin.new(:path => path).code.should == "7hFAQnmt"
90
+ end
85
91
 
86
- it "gets the file" do
87
- skin.download
88
- File.should be_exists(zip_filename)
92
+ it "raises error on wrong code for path" do
93
+ expect do
94
+ Skin.new(:code => "different", :path => path).path.should == path
95
+ end.to raise_error
96
+ end
97
+
98
+ it "raises error on empty code" do
99
+ expect do
100
+ Skin.new
101
+ end.to raise_error
102
+ end
89
103
  end
90
- end
91
104
 
92
- describe "#compile" do
93
- let(:skin_code) { "DV3tf95f" }
94
- let(:skin) { Skin.new(:path => "#{skin_fixtures}/#{skin_code}") }
105
+ describe "#download" do
106
+ let(:zip_filename) { "#{skin.code}.zip"}
107
+ after do
108
+ `rm -rf #{zip_filename}`
109
+ end
95
110
 
96
- def zip_contains(zip_filename, file)
97
- Zip::ZipFile.open(zip_filename, 'r') do |zipfile|
98
- return true if zipfile.find_entry(File.join(skin_code, file))
111
+ it "gets the file" do
112
+ skin.download
113
+ File.should be_exists(zip_filename)
99
114
  end
100
- false
101
115
  end
102
116
 
103
- context "without base" do
104
- before do
105
- `mv #{skin_fixtures}/base #{skin_fixtures}/base2`
117
+ describe "#compile" do
118
+ let(:skin_code) { "DV3tf95f" }
119
+ let(:skin) { Skin.new(:path => "#{skin_fixtures}/#{skin_code}") }
120
+
121
+ def zip_contains(zip_filename, file)
122
+ Zip::ZipFile.open(zip_filename, 'r') do |zipfile|
123
+ return true if zipfile.find_entry(File.join(skin_code, file))
124
+ end
125
+ false
106
126
  end
107
127
 
108
- after do
109
- `mv #{skin_fixtures}/base2 #{skin_fixtures}/base`
128
+ context "without base" do
129
+ before do
130
+ `mv #{skin_fixtures}/base #{skin_fixtures}/base2`
131
+ end
132
+
133
+ after do
134
+ `mv #{skin_fixtures}/base2 #{skin_fixtures}/base`
135
+ end
136
+
137
+ it "includes screen file" do
138
+ zip_contains(skin.compile, "css/screen.css").should be_true
139
+ end
140
+
141
+ it "excludes print files" do
142
+ zip_contains(skin.compile, "css/print.css").should_not be_true
143
+ end
110
144
  end
111
145
 
112
146
  it "includes screen file" do
113
147
  zip_contains(skin.compile, "css/screen.css").should be_true
114
148
  end
115
149
 
116
- it "excludes print files" do
117
- zip_contains(skin.compile, "css/print.css").should_not be_true
150
+ it "includes print file" do
151
+ zip_contains(skin.compile, "css/print.css").should be_true
118
152
  end
119
- end
120
-
121
- it "includes screen file" do
122
- zip_contains(skin.compile, "css/screen.css").should be_true
123
- end
124
153
 
125
- it "includes print file" do
126
- zip_contains(skin.compile, "css/print.css").should be_true
127
- end
128
-
129
- it "excludes meta file" do
130
- zip_contains(skin.compile, "metadata.yml").should_not be_true
131
- end
154
+ it "excludes meta file" do
155
+ zip_contains(skin.compile, "metadata.yml").should_not be_true
156
+ end
132
157
 
133
- it "excludes skin file" do
134
- zip_contains(skin.compile, "skin.html.erb").should_not be_true
158
+ it "excludes skin file" do
159
+ zip_contains(skin.compile, "skin.html.erb").should_not be_true
160
+ end
135
161
  end
136
- end
137
162
 
138
- describe "#upload" do
139
- context "valid set" do
140
- it "increases version" do
141
- skin.path = "#{skin_fixtures}/example-7hFAQnmt"
163
+ describe "#upload" do
164
+ context "valid set" do
165
+ it "increases version" do
166
+ skin.path = "#{skin_fixtures}/example-7hFAQnmt"
142
167
 
143
- expect do
144
- skin.upload
145
- end.to change { skin.version }.by(1)
168
+ expect do
169
+ skin.upload
170
+ end.to change { skin.version }.by(1)
171
+ end
146
172
  end
147
173
  end
148
- end
149
174
 
150
- describe "#version" do
151
- let(:skin) { Skin.new(:code => "Kx9axnRf", :name => "demo") }
175
+ describe "#version" do
176
+ let(:skin) { Skin.new(:code => "Kx9axnRf", :name => "demo") }
152
177
 
153
- it "returns uploaded value" do
154
- skin.version.should == 2
155
- end
178
+ it "returns uploaded value" do
179
+ skin.version.should == 14
180
+ end
156
181
 
157
- it "returns test value" do
158
- skin.version(:test).should == 2
159
- end
182
+ it "returns test value" do
183
+ skin.version(:test).should == 14
184
+ end
160
185
 
161
- it "returns live value" do
162
- skin.version(:live).should == 0
186
+ it "returns live value" do
187
+ skin.version(:live).should == 0
188
+ end
163
189
  end
164
- end
165
190
 
166
- describe "#test_url" do
167
- it "returns url to test" do
168
- skin.test_url.to_s.should include("https://test.adyen.com/hpp/select.shtml")
191
+ describe "#test_url" do
192
+ it "returns url to test" do
193
+ skin.test_url.to_s.should include("https://test.adyen.com/hpp/select.shtml")
194
+ end
195
+ #todo test with options
169
196
  end
170
- #todo test with options
171
197
  end
172
-
173
198
  end
174
199
  end