pingo 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -9
- data/lib/pingo/version.rb +1 -1
- data/lib/pingo.rb +30 -25
- data/spec/pingo_spec.rb +25 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e46197fce732659a1f29c737099474746d885f9
|
4
|
+
data.tar.gz: 543c8ec0bbdf0cdd48eeadb1b246d93ba427b6b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bf5b2aa38d6c5441c256831ddcfa187948823cc99a05732ee635574adba466e273688bbc07932fb32b14ecad37cc11f918bb9b08fa1d0f757a9ab8f2a3cb6b3
|
7
|
+
data.tar.gz: 95e36f1837a12ca45133480a4309bc1c9ff287e8854adc6f8f819b051c3956df103572bda8c653e130b89c7932731543c23431a1adcd5bed6b2239308406ef53
|
data/README.md
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
# Pingo [![Gem Version](https://badge.fury.io/rb/pingo.svg)](http://badge.fury.io/rb/pingo) [![Code Climate](https://codeclimate.com/github/Kyuden/pingo/badges/gpa.svg)](https://codeclimate.com/github/Kyuden/pingo) [![wercker status](https://app.wercker.com/status/8fc989959ae4630aef746364c6ead94f/m/master "wercker status")](https://app.wercker.com/project/bykey/8fc989959ae4630aef746364c6ead94f)
|
2
2
|
|
3
|
+
<p><img width="400"src="http://www.fastpic.jp/images.php?file=8622347177.jpg"></p>
|
3
4
|
Pingo provide a scatterbrain with a `pingo` command of sounding your iphone.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
gem 'pingo'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
8
|
+
Install it yourself as:
|
16
9
|
|
17
10
|
$ gem install pingo
|
18
11
|
|
@@ -38,6 +31,8 @@ Example:
|
|
38
31
|
```
|
39
32
|
# when iphone 5s
|
40
33
|
pingo 5s
|
34
|
+
# when iphone 6
|
35
|
+
pingo 6
|
41
36
|
# when iphone 6 Plus
|
42
37
|
pingo 6.Plus
|
43
38
|
```
|
data/lib/pingo/version.rb
CHANGED
data/lib/pingo.rb
CHANGED
@@ -11,9 +11,9 @@ module Pingo
|
|
11
11
|
class << self
|
12
12
|
def run(model_name)
|
13
13
|
new(model_name).instance_eval do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
partition = request_partition
|
15
|
+
device_ids = request_device_ids(partition)
|
16
|
+
request_sound(partition, device_ids)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -25,20 +25,21 @@ module Pingo
|
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
|
-
def
|
28
|
+
def request_partition
|
29
29
|
post(INIT_CLIENT).headers['X-Apple-MMe-Host']
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def request_device_ids(partition)
|
33
|
+
raise "partition is nil" unless partition
|
34
|
+
parse_device_ids(post(INIT_CLIENT, partition))
|
34
35
|
end
|
35
36
|
|
36
|
-
def
|
37
|
-
|
37
|
+
def parse_device_ids(data)
|
38
|
+
target_contents(data).map { |content| content["id"] }
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
-
|
41
|
+
def target_contents(data)
|
42
|
+
contents(data).find_all { |content| match_device?(content) }
|
42
43
|
end
|
43
44
|
|
44
45
|
def contents(data)
|
@@ -46,31 +47,39 @@ module Pingo
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def match_device?(params)
|
49
|
-
params['
|
50
|
+
params['deviceDisplayName'] =~ /#{@model_name}$/i
|
50
51
|
end
|
51
52
|
|
52
|
-
def
|
53
|
-
|
53
|
+
def request_sound(partition, device_ids)
|
54
|
+
raise "partition is nil" unless partition
|
55
|
+
raise "device id is nil" if Array(device_ids).empty?
|
56
|
+
Array(device_ids).map { |device_id| post(PLAY_SOUND, partition, generate_body(device_id)) }
|
54
57
|
end
|
55
58
|
|
56
|
-
def generate_body
|
57
|
-
JSON.generate(
|
59
|
+
def generate_body(device_id)
|
60
|
+
JSON.generate(sound_body(device_id))
|
58
61
|
end
|
59
62
|
|
60
|
-
def
|
63
|
+
def sound_body(device_id)
|
61
64
|
{
|
62
65
|
clientContext: {
|
63
66
|
appName: 'FindMyiPhone',
|
64
67
|
appVersion: '2.0.2',
|
65
68
|
shouldLocate: false,
|
66
69
|
},
|
67
|
-
device:
|
70
|
+
device: device_id,
|
68
71
|
subject: "Pingo"
|
69
72
|
}
|
70
73
|
end
|
71
74
|
|
72
|
-
def post(mode, body=nil)
|
73
|
-
Typhoeus::Request.post(uri(mode
|
75
|
+
def post(mode, partition="fmipmobile.icloud.com", body=nil)
|
76
|
+
Typhoeus::Request.post(uri(mode, partition),
|
77
|
+
userpwd: "#{@username}:#{@password}",
|
78
|
+
headers: post_headers,
|
79
|
+
followlocation: true,
|
80
|
+
verbose: true,
|
81
|
+
maxredirs: 1,
|
82
|
+
body: body)
|
74
83
|
end
|
75
84
|
|
76
85
|
def post_headers
|
@@ -85,12 +94,8 @@ module Pingo
|
|
85
94
|
}
|
86
95
|
end
|
87
96
|
|
88
|
-
def uri(mode)
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
def base_uri
|
93
|
-
"fmipservice/device/#{@username}"
|
97
|
+
def uri(mode, partition)
|
98
|
+
"https://#{partition}/fmipservice/device/#{@username}/#{mode}"
|
94
99
|
end
|
95
100
|
end
|
96
101
|
end
|
data/spec/pingo_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Pingo do
|
|
5
5
|
expect(Pingo::VERSION).not_to be_nil
|
6
6
|
end
|
7
7
|
|
8
|
-
describe "
|
8
|
+
describe "#request_partition" do
|
9
9
|
subject { Pingo::Pingo.new("5s") }
|
10
10
|
|
11
11
|
context 'valid APPLE_ID and APPLE_PASSWORD in ENV' do
|
@@ -13,7 +13,7 @@ describe Pingo do
|
|
13
13
|
|
14
14
|
it 'should return partition' do
|
15
15
|
VCR.use_cassette 'init_client/partition/valid_interaction' do
|
16
|
-
expect(subject.send(:
|
16
|
+
expect(subject.send(:request_partition)).not_to be_nil
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -23,13 +23,13 @@ describe Pingo do
|
|
23
23
|
|
24
24
|
it 'should not return partition' do
|
25
25
|
VCR.use_cassette 'init_client/partition/invalid_interaction' do
|
26
|
-
expect(subject.send(:
|
26
|
+
expect(subject.send(:request_partition)).to be_nil
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe "
|
32
|
+
describe "#request_device_ids" do
|
33
33
|
before { set_valid_env }
|
34
34
|
let!(:pingo) { Pingo::Pingo.new(model_name) }
|
35
35
|
|
@@ -38,10 +38,10 @@ describe Pingo do
|
|
38
38
|
|
39
39
|
it 'should return device_id' do
|
40
40
|
VCR.use_cassette 'init_client/partition/valid_interaction' do
|
41
|
-
|
41
|
+
partition = pingo.send(:request_partition)
|
42
42
|
|
43
43
|
VCR.use_cassette 'init_client/device_id/valid_interaction' do
|
44
|
-
expect(pingo.send(:
|
44
|
+
expect(pingo.send(:request_device_ids, partition)).not_to be_nil
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -52,35 +52,35 @@ describe Pingo do
|
|
52
52
|
|
53
53
|
it 'should not return device_id' do
|
54
54
|
VCR.use_cassette 'init_client/partition/valid_interaction' do
|
55
|
-
|
55
|
+
partition = pingo.send(:request_partition)
|
56
56
|
|
57
57
|
VCR.use_cassette 'init_client/device_id/invalid_interaction' do
|
58
|
-
expect(pingo.send(:
|
58
|
+
expect(pingo.send(:request_device_ids, partition)).to eq([])
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe "
|
65
|
+
describe "#request_sound" do
|
66
66
|
before { set_valid_env }
|
67
67
|
let!(:pingo) { Pingo::Pingo.new("5s") }
|
68
68
|
|
69
69
|
context 'valid device_id' do
|
70
|
-
before do
|
71
|
-
pingo.instance_variable_set(:@device_id, nil)
|
72
|
-
end
|
73
|
-
|
74
70
|
it 'should return 200 of status code' do
|
75
71
|
VCR.use_cassette 'init_client/partition/valid_interaction' do
|
76
|
-
|
72
|
+
partition = pingo.send(:request_partition)
|
77
73
|
|
78
74
|
VCR.use_cassette 'init_client/device_id/valid_interaction' do
|
79
|
-
|
75
|
+
device_ids = pingo.send(:request_device_ids, partition)
|
80
76
|
|
81
77
|
VCR.use_cassette 'play_sound/valid_interaction' do
|
82
|
-
|
83
|
-
|
78
|
+
responses = pingo.send(:request_sound, partition, device_ids)
|
79
|
+
|
80
|
+
responses.each do |response|
|
81
|
+
# VCR response structure and typhoeus it are differ even
|
82
|
+
expect([response.code, response.response_code]).to include(200)
|
83
|
+
end
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -88,22 +88,22 @@ describe Pingo do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
context 'invalid device_id' do
|
91
|
-
|
92
|
-
pingo.instance_variable_set(:@device_id, nil)
|
93
|
-
end
|
91
|
+
let!(:device_ids) { "invalid device id" }
|
94
92
|
|
95
93
|
it 'should return 500 of status code' do
|
96
94
|
VCR.use_cassette 'init_client/partition/valid_interaction' do
|
97
|
-
|
95
|
+
partition = pingo.send(:request_partition)
|
98
96
|
|
99
97
|
VCR.use_cassette 'init_client/device_id/valid_interaction' do
|
100
|
-
pingo.send(:
|
98
|
+
pingo.send(:request_device_ids, partition)
|
101
99
|
|
102
100
|
VCR.use_cassette 'play_sound/invalid_interaction' do
|
103
|
-
|
101
|
+
responses = pingo.send(:request_sound, partition, device_ids)
|
104
102
|
|
105
|
-
|
106
|
-
|
103
|
+
responses.each do |response|
|
104
|
+
# VCR response structure and typhoeus it are differ even
|
105
|
+
expect([response.code, response.response_code]).to include(500)
|
106
|
+
end
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pingo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyuden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|