fsync-client 0.0.2.pre → 0.0.3.pre

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2.pre
1
+ 0.0.3.pre
@@ -6,16 +6,13 @@ class FinanceSync
6
6
 
7
7
  attr_reader :version, :entities, :conflicts, :error
8
8
 
9
- def initialize(params)
10
- @services_url = params[:services_url]
11
- @version = params[:version]
12
- @user = params[:user]
13
- @password = params[:password]
14
- raise ArgumentError if @user.nil? or @password.nil?
15
- raise TypeError unless @version.is_a? Fixnum
16
-
9
+ def initialize(url, version, token)
10
+ @services_url = url
11
+ @version = version
12
+ @token = token
17
13
  @error = nil
18
14
  @conflicts = []
15
+ raise TypeError unless @version.is_a? Fixnum
19
16
  end
20
17
 
21
18
  def synchronize(data)
@@ -38,8 +35,8 @@ class FinanceSync
38
35
  errors = {"400"=>"bad data", "500"=>"sync server error",
39
36
  "423"=>"locked", "401"=> "login error"}
40
37
 
41
- put = Net::HTTP::Put.new("/financedesktop/sync/synchronize")
42
- put.basic_auth(@user, @password)
38
+ put = Net::HTTP::Put.new("/financedesktop/sync/synchronize?auth=myfc_id")
39
+ put.basic_auth('', @token)
43
40
  put.content_type = 'application/json'
44
41
  begin
45
42
  response = Net::HTTP.start(@services_url) {|http|
@@ -17,30 +17,30 @@ UPDATED_VERSION = '{"conflicts": [], "version": 49, "data": [{"entity": {"import
17
17
  "date": "2010-10-11", "guid": "22a648b0-2fe1-4888-96a4-caa27a4c27d7",
18
18
  "type": "transaction"}}]}'
19
19
 
20
- USER = 'jalim'
21
- PASSWORD = 'habei'
20
+ TOKEN = 'ageneratedtoken'
22
21
 
23
22
  describe "Finance Sync API wrapper" do
24
23
 
25
- def fake_sync_response(response, user='', password='')
26
- if not (user.empty? and password.empty?)
27
- credentials = "#{user}:#{password}@"
24
+ def fake_sync_response(response, token='')
25
+ if not (token.empty?)
26
+ credentials = ":#{token}@"
28
27
  else
29
28
  credentials = ""
30
29
  end
31
30
 
32
31
  FakeWeb.register_uri(
33
32
  :put,
34
- "http://#{credentials}services.myfreecomm.com.br/financedesktop/sync/synchronize",
33
+ "http://#{credentials}services.myfreecomm.com.br/financedesktop/sync/synchronize?auth=myfc_id",
35
34
  response)
36
35
  end
37
36
 
38
37
  before(:each) do
39
38
  @services_url = "services.myfreecomm.com.br"
40
- @finance_sync = FinanceSync.new(:services_url => @services_url, :version => 2,
41
- :user=>USER, :password=>PASSWORD)
39
+ @finance_sync = FinanceSync.new(@services_url, version = 2,
40
+ token = TOKEN)
42
41
  end
43
42
 
43
+
44
44
  describe "initializer" do
45
45
 
46
46
  it "should store version" do
@@ -54,8 +54,8 @@ describe "Finance Sync API wrapper" do
54
54
  end
55
55
 
56
56
  it "should have .version" do
57
- @finance_sync = FinanceSync.new(:services_url=>@services_url, :version => 4,
58
- :user=>USER, :password=>PASSWORD)
57
+ @finance_sync = FinanceSync.new(@services_url, version = 4,
58
+ token = TOKEN)
59
59
  @finance_sync.version.should == 4
60
60
  end
61
61
 
@@ -63,13 +63,13 @@ describe "Finance Sync API wrapper" do
63
63
 
64
64
  it "should send the params formed correctly" do
65
65
 
66
- @finance_sync = FinanceSync.new(:services_url => @services_url, :version => 48,
67
- :user=>USER, :password=>PASSWORD)
66
+ @finance_sync = FinanceSync.new(@services_url, version = 48,
67
+ token = TOKEN)
68
68
  correct_json = {"version"=>@finance_sync.version, "data"=>ENTITIES}.to_json
69
69
 
70
70
  put = mock(Net::HTTP::Put)
71
- Net::HTTP::Put.should_receive(:new).with("/financedesktop/sync/synchronize").once.and_return(put)
72
- put.should_receive(:basic_auth).with(USER, PASSWORD)
71
+ Net::HTTP::Put.should_receive(:new).with("/financedesktop/sync/synchronize?auth=myfc_id").once.and_return(put)
72
+ put.should_receive(:basic_auth).with('', TOKEN)
73
73
  put.should_receive(:content_type=).with('application/json')
74
74
 
75
75
  http = mock()
@@ -88,13 +88,13 @@ describe "Finance Sync API wrapper" do
88
88
 
89
89
  before(:each) do
90
90
  @invalid_url = 'invalid_url'
91
- @finance_sync = FinanceSync.new(:services_url => @invalid_url, :version => 48,
92
- :user=>USER, :password=>PASSWORD)
91
+ @finance_sync = FinanceSync.new(@invalid_url, version = 48,
92
+ token = TOKEN)
93
93
  @correct_json = {"version"=>@finance_sync.version, "data"=>ENTITIES}.to_json
94
94
 
95
95
  @put = mock(Net::HTTP::Put)
96
- Net::HTTP::Put.should_receive(:new).with("/financedesktop/sync/synchronize").once.and_return(@put)
97
- @put.should_receive(:basic_auth).with(USER, PASSWORD)
96
+ Net::HTTP::Put.should_receive(:new).with("/financedesktop/sync/synchronize?auth=myfc_id").once.and_return(@put)
97
+ @put.should_receive(:basic_auth).with("", TOKEN)
98
98
  @put.should_receive(:content_type=).with('application/json')
99
99
  http = mock()
100
100
  Net::HTTP.should_receive(:start).with(@invalid_url).and_raise(SocketError)
@@ -116,8 +116,8 @@ describe "Finance Sync API wrapper" do
116
116
  describe "with invalid url" do
117
117
 
118
118
  before(:each) do
119
- @finance_sync = FinanceSync.new(:services_url => nil, :version => 48,
120
- :user=>USER, :password=>PASSWORD)
119
+ @finance_sync = FinanceSync.new(nil, version = 48,
120
+ token = TOKEN)
121
121
  end
122
122
 
123
123
  it "should return false" do
@@ -133,10 +133,10 @@ describe "Finance Sync API wrapper" do
133
133
 
134
134
  describe "with invalid version specified" do
135
135
  it "should raise TypeError if a non integer is passed " do
136
- wrong_params = {:services_url => "services.myfreecomm.com.br",
137
- :version => "abcsd", :user=>USER, :password=>PASSWORD}
136
+ wrong_params = {:url => "services.myfreecomm.com.br",
137
+ :version => "abcsd", :token => TOKEN}
138
138
  lambda {
139
- FinanceSync.new(wrong_params)
139
+ FinanceSync.new(*wrong_params)
140
140
  }.should raise_exception(TypeError)
141
141
 
142
142
  end
@@ -145,9 +145,9 @@ describe "Finance Sync API wrapper" do
145
145
  describe "with wrong credentials provided" do
146
146
 
147
147
  before(:each) do
148
- fake_sync_response({:status=>[401, "unauthorized"]}, 'wrong', 'credential' )
149
- @finance_sync = FinanceSync.new(:services_url => @services_url, :version => 48,
150
- :user=>'wrong', :password=>'credential')
148
+ fake_sync_response({:status=>[401, "unauthorized"]}, 'wrongtoken' )
149
+ @finance_sync = FinanceSync.new(@services_url, version = 48,
150
+ token = 'wrongtoken')
151
151
  end
152
152
 
153
153
  it "should return false " do
@@ -165,7 +165,7 @@ describe "Finance Sync API wrapper" do
165
165
 
166
166
  it "should raise 'Argument Error'" do
167
167
  lambda {
168
- FinanceSync.new(:services_url => @services_url, :version => 48)
168
+ FinanceSync.new(@services_url, version = 48)
169
169
  }.should raise_exception(ArgumentError)
170
170
  end
171
171
  end
@@ -173,12 +173,11 @@ describe "Finance Sync API wrapper" do
173
173
  describe "with no conflicts and no new data" do
174
174
 
175
175
  before(:each) do
176
- @finance_sync = FinanceSync.new(:services_url => "services.myfreecomm.com.br",
177
- :version => 48, :user=>'wrong',
178
- :password=>'credentials' )
176
+ @finance_sync = FinanceSync.new("services.myfreecomm.com.br",
177
+ version = 48, token ='atoken' )
179
178
  fake_sync_response({:status=>[200, "OK"],
180
179
  :body=>'{"conflicts": [], "version": 48, "data": []}'},
181
- 'wrong', 'credentials')
180
+ 'atoken')
182
181
  end
183
182
 
184
183
  it "should not update version" do
@@ -204,11 +203,10 @@ describe "Finance Sync API wrapper" do
204
203
 
205
204
  before(:each) do
206
205
 
207
- @finance_sync = FinanceSync.new(:services_url => "services.myfreecomm.com.br",
208
- :version => 48, :user=>'wrong',
209
- :password=>'credentials')
206
+ @finance_sync = FinanceSync.new("services.myfreecomm.com.br",
207
+ version = 48, token = 'wrongtoken')
210
208
  fake_sync_response({:status=>[200, "OK"], :body=>UPDATED_VERSION},
211
- 'wrong', 'credentials')
209
+ 'wrongtoken')
212
210
 
213
211
  end
214
212
 
@@ -241,7 +239,7 @@ describe "Finance Sync API wrapper" do
241
239
 
242
240
  before(:each) do
243
241
  fake_sync_response({:status=>[400, "Bad request"], :body=>"invalid data"},
244
- USER, PASSWORD)
242
+ TOKEN)
245
243
  @bad_data = '{"version": 47, "entity":}'
246
244
  end
247
245
 
@@ -260,7 +258,7 @@ describe "Finance Sync API wrapper" do
260
258
 
261
259
  before(:each) do
262
260
  fake_sync_response({:status=>[500, "Server Error"], :body=>"Server Error"},
263
- USER, PASSWORD)
261
+ TOKEN)
264
262
  @valid_data = '{"valid": "data"}'
265
263
  end
266
264
 
@@ -278,7 +276,7 @@ describe "Finance Sync API wrapper" do
278
276
  describe "on sync server lock" do
279
277
 
280
278
  before(:each) do
281
- fake_sync_response({:status=>[423, "Locked"], :body=>"Locked"}, USER, PASSWORD)
279
+ fake_sync_response({:status=>[423, "Locked"], :body=>"Locked"}, TOKEN)
282
280
  @valid_data = '{"valid": "data"}'
283
281
  end
284
282
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fsync-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 961915980
4
+ hash: 961915976
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
9
+ - 3
10
10
  - pre
11
- version: 0.0.2.pre
11
+ version: 0.0.3.pre
12
12
  platform: ruby
13
13
  authors:
14
14
  - Vanderson Mota
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-03 00:00:00 -02:00
19
+ date: 2010-12-16 00:00:00 -02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency