BtSync 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA512:
3
- metadata.gz: 836f4bb22c32ea95ae660a7552e54de2ac5b862d7a661619e8d8e2f9dcf85ebc3f2a4ec0660ac6fdf47b59a639c67a54d657a40741f4673ad8669fa59a40075b
4
- data.tar.gz: 23476217aa90091abe25801ec24a7524b8b2c9ef8465d6a60395395e78d5b6a58f547f67b2185dc76da3d22ec908fdb10cb06651f7dde24c5c11a64a7d61dfd6
5
2
  SHA1:
6
- metadata.gz: b0f8fbda9f18fe7d8e42acf16d036a9ed52675df
7
- data.tar.gz: 316de2ce209f019a82e8300cae406a044af318ee
3
+ data.tar.gz: 184a18c62f1a7ad68f7925a77bce8782cb25d247
4
+ metadata.gz: ce45b9891ffa8bae8c8b32ecb0f6910aea2a4236
5
+ SHA512:
6
+ data.tar.gz: b9c16407995447411d8babfdfb4e62ce9d3af3ba7a4a638a47a3a5a2c218008f6e0ce2da86c7f496fd8156b1bc453e3ad20baaadd8f379f7abecaf9ecb671d8c
7
+ metadata.gz: 6a096011dd2794ccaa9fdf4c0f363137e48b1b1dc4e9c1852f9fd725f10d55a65b7e402cf74c6b02fa10f49b8dd859451642b092d866e5b3c2a074c3b0cc771d
@@ -20,8 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "vcr"
23
26
 
24
27
  spec.add_runtime_dependency "httparty"
25
28
  spec.add_runtime_dependency "nokogiri"
26
- spec.add_runtime_dependency "json"
27
29
  end
@@ -1,8 +1,7 @@
1
1
  require 'httparty'
2
2
  require 'nokogiri'
3
- require 'json'
4
3
 
5
- class Btsync
4
+ class BtSync
6
5
  include HTTParty
7
6
  def initialize uri=nil, port=nil
8
7
  @cache = {
@@ -10,6 +9,7 @@ class Btsync
10
9
  :secret => 0,
11
10
  :settings => 0,
12
11
  :os_type => 0,
12
+ :version => 0,
13
13
  :new_version => 0
14
14
  }
15
15
  @uri = uri
@@ -48,7 +48,7 @@ class Btsync
48
48
  time = DateTime.now.strftime("%s").to_i
49
49
  if time > @cache[:version] + 600
50
50
  res = self.class.get(path('getversion'), :query => {:output => "json"}, :headers => {"Cookie" => cookies })
51
- @version = res.parsed_response
51
+ @version = res.parsed_response["version"]
52
52
  @cache[:version] = time
53
53
  end
54
54
  @version
@@ -95,7 +95,7 @@ class Btsync
95
95
  @cookies ||= request_token.headers["set-cookie"].split("; ")[0]
96
96
  end
97
97
  def request_token
98
- @request_token ||= self.class.get("#{uri}:#{port}/gui/token.html?t=" + DateTime.now.strftime('%s'))
98
+ @request_token ||= self.class.get("#{uri}:#{port}/gui/token.html")
99
99
  end
100
100
  def path action_name
101
101
  "#{uri}:#{port}/gui/?token=#{secret}&action=#{action_name}"
@@ -1,3 +1,3 @@
1
1
  module BtsyncVersion
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+ require 'btsync'
3
+ describe 'BtSync' do
4
+ before do
5
+ VCR.use_cassette("Setup-BtSync") do
6
+ @bt = BtSync.new
7
+ end
8
+ end
9
+ it "can view a folder list" do
10
+ VCR.use_cassette("get-folders") do
11
+ @folder = @bt.get_folders.first
12
+ end
13
+ @folder["secret"].should == "KLXT6ZZBEABLFIL6X7VBHT7YA4YQQOJM"
14
+ @folder["peers"].should == []
15
+ @folder["size"].should == "21 B in 1 files"
16
+ end
17
+ it "can view settings" do
18
+ VCR.use_cassette("get-settings") do
19
+ @settings = @bt.get_settings
20
+ end
21
+ @settings["devicename"].should == "IceyEC-Virtual1"
22
+ @settings["listeningport"].should == 63754
23
+ end
24
+ it "can check the OS" do
25
+ VCR.use_cassette("get-os-type") do
26
+ @os = @bt.get_os_type
27
+ end
28
+ @os.should == "linux"
29
+ end
30
+ it "can get the version" do
31
+ VCR.use_cassette("get-version") do
32
+ @version = @bt.get_version
33
+ end
34
+ @version.should == 16777350
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ ---
2
+ recorded_with: VCR 2.5.0
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: http://localhost:8888/gui/token.html
7
+ body:
8
+ string: ""
9
+ headers: {}
10
+
11
+ response:
12
+ status:
13
+ code: 200
14
+ message: OK
15
+ headers:
16
+ Set-Cookie:
17
+ - GUID=SklJvMPAaAAUrQIQ3W3i; path=/
18
+ Connection:
19
+ - keep-alive
20
+ Content-Type:
21
+ - text/html
22
+ Content-Length:
23
+ - "121"
24
+ Cache-Control:
25
+ - no-cache
26
+ body:
27
+ string: <html><div id='token' style='display:none;'>grsJ7BMbd6FPJND8DVjjZBZdHKV44iACI83vsaYfENHJYr2peP4GJdU7rlEAAAAA</div></html>
28
+ http_version:
29
+ recorded_at: Tue, 04 Jun 2013 19:11:20 GMT
@@ -0,0 +1,28 @@
1
+ ---
2
+ recorded_with: VCR 2.5.0
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: http://localhost:8888/gui/?action=getsyncfolders&output=json&token=grsJ7BMbd6FPJND8DVjjZBZdHKV44iACI83vsaYfENHJYr2peP4GJdU7rlEAAAAA
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Cookie:
11
+ - GUID=SklJvMPAaAAUrQIQ3W3i
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Connection:
18
+ - keep-alive
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - "186"
23
+ Cache-Control:
24
+ - no-cache
25
+ body:
26
+ string: "{ \"folders\": [ { \"name\": \"\\/home\\/chris\\/Documents\", \"peers\": [ ], \"secret\": \"KLXT6ZZBEABLFIL6X7VBHT7YA4YQQOJM\", \"size\": \"21 B in 1 files\" } ], \"speed\": \"0.0 kB\\/s up, 0.0 kB\\/s down\" }"
27
+ http_version:
28
+ recorded_at: Tue, 04 Jun 2013 19:11:20 GMT
@@ -0,0 +1,28 @@
1
+ ---
2
+ recorded_with: VCR 2.5.0
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: http://localhost:8888/gui/?action=getostype&output=json&token=grsJ7BMbd6FPJND8DVjjZBZdHKV44iACI83vsaYfENHJYr2peP4GJdU7rlEAAAAA
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Cookie:
11
+ - GUID=SklJvMPAaAAUrQIQ3W3i
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Connection:
18
+ - keep-alive
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - "17"
23
+ Cache-Control:
24
+ - no-cache
25
+ body:
26
+ string: "{ \"os\": \"linux\" }"
27
+ http_version:
28
+ recorded_at: Tue, 04 Jun 2013 19:11:20 GMT
@@ -0,0 +1,28 @@
1
+ ---
2
+ recorded_with: VCR 2.5.0
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: http://localhost:8888/gui/?action=getsettings&output=json&token=grsJ7BMbd6FPJND8DVjjZBZdHKV44iACI83vsaYfENHJYr2peP4GJdU7rlEAAAAA
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Cookie:
11
+ - GUID=SklJvMPAaAAUrQIQ3W3i
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Connection:
18
+ - keep-alive
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - "119"
23
+ Cache-Control:
24
+ - no-cache
25
+ body:
26
+ string: "{ \"settings\": { \"devicename\": \"IceyEC-Virtual1\", \"dlrate\": 0, \"listeningport\": 63754, \"portmapping\": 1, \"ulrate\": 0 } }"
27
+ http_version:
28
+ recorded_at: Tue, 04 Jun 2013 19:11:20 GMT
@@ -0,0 +1,28 @@
1
+ ---
2
+ recorded_with: VCR 2.5.0
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: http://localhost:8888/gui/?action=getversion&output=json&token=grsJ7BMbd6FPJND8DVjjZBZdHKV44iACI83vsaYfENHJYr2peP4GJdU7rlEAAAAA
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Cookie:
11
+ - GUID=SklJvMPAaAAUrQIQ3W3i
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Connection:
18
+ - keep-alive
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - "23"
23
+ Cache-Control:
24
+ - no-cache
25
+ body:
26
+ string: "{ \"version\": 16777350 }"
27
+ http_version:
28
+ recorded_at: Tue, 04 Jun 2013 19:11:20 GMT
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "BtSync"
4
+ require 'vcr'
5
+ require 'webmock'
6
+
7
+ def file_fixture(filename)
8
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
9
+ end
10
+
11
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+
15
+ end
16
+
17
+ VCR.configure do |c|
18
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
19
+ c.hook_into :webmock # or :fakeweb
20
+ c.ignore_request { |request| URI(request.uri).host =~ /api\.elocal\.com|127\.0\.0\.1/ }
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BtSync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris MacNaughton
@@ -33,29 +33,45 @@ dependencies:
33
33
  type: :development
34
34
  version_requirements: *id002
35
35
  - !ruby/object:Gem::Dependency
36
- name: httparty
36
+ name: rspec
37
37
  prerelease: false
38
38
  requirement: &id004 !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - *id003
41
- type: :runtime
41
+ type: :development
42
42
  version_requirements: *id004
43
43
  - !ruby/object:Gem::Dependency
44
- name: nokogiri
44
+ name: webmock
45
45
  prerelease: false
46
46
  requirement: &id005 !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - *id003
49
- type: :runtime
49
+ type: :development
50
50
  version_requirements: *id005
51
51
  - !ruby/object:Gem::Dependency
52
- name: json
52
+ name: vcr
53
53
  prerelease: false
54
54
  requirement: &id006 !ruby/object:Gem::Requirement
55
55
  requirements:
56
56
  - *id003
57
- type: :runtime
57
+ type: :development
58
58
  version_requirements: *id006
59
+ - !ruby/object:Gem::Dependency
60
+ name: httparty
61
+ prerelease: false
62
+ requirement: &id007 !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - *id003
65
+ type: :runtime
66
+ version_requirements: *id007
67
+ - !ruby/object:Gem::Dependency
68
+ name: nokogiri
69
+ prerelease: false
70
+ requirement: &id008 !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - *id003
73
+ type: :runtime
74
+ version_requirements: *id008
59
75
  description: Class to interact with BTSync's web interface using their unofficial API
60
76
  email:
61
77
  - chmacnaughton@gmail.com
@@ -76,6 +92,13 @@ files:
76
92
  - btsync.gemspec
77
93
  - lib/btsync.rb
78
94
  - lib/btsync/version.rb
95
+ - spec/BtSync/bt_sync_spec.rb
96
+ - spec/fixtures/cassettes/Setup-BtSync.yml
97
+ - spec/fixtures/cassettes/get-folders.yml
98
+ - spec/fixtures/cassettes/get-os-type.yml
99
+ - spec/fixtures/cassettes/get-settings.yml
100
+ - spec/fixtures/cassettes/get-version.yml
101
+ - spec/spec_helper.rb
79
102
  homepage: http://chrismacnaughton.com/projects#btsync
80
103
  licenses:
81
104
  - MIT
@@ -99,5 +122,11 @@ rubygems_version: 2.0.3
99
122
  signing_key:
100
123
  specification_version: 4
101
124
  summary: Class to interact with BTSync's web interface
102
- test_files: []
103
-
125
+ test_files:
126
+ - spec/BtSync/bt_sync_spec.rb
127
+ - spec/fixtures/cassettes/Setup-BtSync.yml
128
+ - spec/fixtures/cassettes/get-folders.yml
129
+ - spec/fixtures/cassettes/get-os-type.yml
130
+ - spec/fixtures/cassettes/get-settings.yml
131
+ - spec/fixtures/cassettes/get-version.yml
132
+ - spec/spec_helper.rb