nikeplus 0.0.1
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/lib/nike_plus/profile.rb +7 -0
- data/lib/nike_plus/profile_factory.rb +37 -0
- data/lib/nike_plus/request_processor.rb +26 -0
- data/lib/nike_plus/session.rb +18 -0
- data/lib/nike_plus/session_factory.rb +28 -0
- data/lib/nike_plus.rb +8 -0
- data/lib/nikeplus.rb +2 -0
- metadata +83 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
module NikePlus
|
2
|
+
|
3
|
+
class ProfileFactory
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def create_from_profile_html(name, html)
|
8
|
+
profile_data = extract_baked_data(html)
|
9
|
+
Profile.new(name, friends(profile_data), distance_ran(profile_data))
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def extract_baked_data(profile_html)
|
15
|
+
if /<script>\s*window.np.baked_data\s*=\s*(.*?)\s*;\s*<\/script>/ =~ profile_html
|
16
|
+
Yajl::Parser.parse($1, symbolize_keys: true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def friends(profile)
|
21
|
+
profile[:friendsList][:friends].map { |friend| friend[:name] }
|
22
|
+
end
|
23
|
+
|
24
|
+
def distance_ran(profile)
|
25
|
+
profile[:userTotals].each do |total|
|
26
|
+
return total[:metrics][:lifetimeTotalDistance] if total[:activityType] == 'running'
|
27
|
+
end
|
28
|
+
0
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
private_constant :ProfileFactory
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NikePlus
|
2
|
+
|
3
|
+
protected
|
4
|
+
|
5
|
+
class RequestProcessor
|
6
|
+
|
7
|
+
def initialize(cookies)
|
8
|
+
@cookies = cookies
|
9
|
+
@http = Net::HTTP.new("nikeplus.nike.com", 80)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(path)
|
13
|
+
req = Net::HTTP::Get.new(path)
|
14
|
+
@cookies.each do |cookie|
|
15
|
+
req['Cookie'] = cookie
|
16
|
+
end
|
17
|
+
|
18
|
+
res = @http.request(req)
|
19
|
+
res.body
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
private_constant :RequestProcessor
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module NikePlus
|
2
|
+
|
3
|
+
class Session
|
4
|
+
|
5
|
+
def initialize(request_processor)
|
6
|
+
@request_processor = request_processor
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_profile(name)
|
10
|
+
ProfileFactory.create_from_profile_html(name, @request_processor.get("/plus/profile/#{name}/"))
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
private_constant :Session
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module NikePlus
|
2
|
+
|
3
|
+
class SessionFactory
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def create(login, password)
|
7
|
+
cookies = authenticate_http_request(login, password)
|
8
|
+
return nil if cookies.nil? || cookies.include?('llCheck=N')
|
9
|
+
Session.new RequestProcessor.new(cookies)
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def authenticate_http_request(login, password)
|
15
|
+
http = Net::HTTP.new("www.nike.com", 443)
|
16
|
+
http.use_ssl = true
|
17
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
18
|
+
|
19
|
+
req = Net::HTTP::Post.new('/profile/login')
|
20
|
+
req.form_data = { login: login, password: password }
|
21
|
+
res = http.request(req)
|
22
|
+
res.get_fields('set-cookie').map { |item| item.split('; ')[0] }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/nike_plus.rb
ADDED
data/lib/nikeplus.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nikeplus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Kasatenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: NikePlus interface implementation
|
47
|
+
email: sky.31338@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/nike_plus/profile.rb
|
53
|
+
- lib/nike_plus/profile_factory.rb
|
54
|
+
- lib/nike_plus/request_processor.rb
|
55
|
+
- lib/nike_plus/session.rb
|
56
|
+
- lib/nike_plus/session_factory.rb
|
57
|
+
- lib/nike_plus.rb
|
58
|
+
- lib/nikeplus.rb
|
59
|
+
homepage: http://rubygems.org/gems/nikeplus
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.25
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: NikePlus interface implementation
|
83
|
+
test_files: []
|