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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bf1c1c7fe43c0886997ec14ebb6165172805761
4
- data.tar.gz: 99539950b36b387a157233d1a1c3d00aab4103db
3
+ metadata.gz: 8e46197fce732659a1f29c737099474746d885f9
4
+ data.tar.gz: 543c8ec0bbdf0cdd48eeadb1b246d93ba427b6b4
5
5
  SHA512:
6
- metadata.gz: eeb32ddcbb2a4d5bfdf194faac47624c68cdd84d394cec19cc92476117f70e4da7321d3ddc9d50365ecf4c3cf343abb4784eaa095eaf87ff5e96a49c409e5943
7
- data.tar.gz: 965645413831e7cf57ac26a771308e96d28ba664dddeb51779916597f98c71f8e151d5ada45a8c6f6d24cdad9818c6bc68c88c3f886950652f7fd9829cf75d64
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
- Add this line to your application's Gemfile:
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
@@ -1,3 +1,3 @@
1
1
  module Pingo
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
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
- @partition = get_partition
15
- @device_id = get_device_id
16
- play_sound
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 get_partition
28
+ def request_partition
29
29
  post(INIT_CLIENT).headers['X-Apple-MMe-Host']
30
30
  end
31
31
 
32
- def get_device_id
33
- parse_device_id(post(INIT_CLIENT))
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 parse_device_id(data)
37
- target_content(data) ? target_content(data)["id"] : nil
37
+ def parse_device_ids(data)
38
+ target_contents(data).map { |content| content["id"] }
38
39
  end
39
40
 
40
- def target_content(data)
41
- @target_content ||= contents(data).find { |content| match_device?(content) }
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['location'] && params['deviceDisplayName'] =~ /#{@model_name}$/i
50
+ params['deviceDisplayName'] =~ /#{@model_name}$/i
50
51
  end
51
52
 
52
- def play_sound
53
- post(PLAY_SOUND, generate_body)
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(play_sound_body)
59
+ def generate_body(device_id)
60
+ JSON.generate(sound_body(device_id))
58
61
  end
59
62
 
60
- def play_sound_body
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: @device_id,
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), userpwd: "#{@username}:#{@password}", headers: post_headers, followlocation: true, verbose: true, maxredirs: 1, body: body)
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
- @partition ? "https://#{@partition}/#{base_uri}/#{mode}" : "https://fmipmobile.icloud.com/#{base_uri}/#{mode}"
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 ".get_partiotion" do
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(:get_partition)).not_to be_nil
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(:get_partition)).to be_nil
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 ".get_device_id" do
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
- pingo.instance_variable_set(:@partition, pingo.send(:get_partition))
41
+ partition = pingo.send(:request_partition)
42
42
 
43
43
  VCR.use_cassette 'init_client/device_id/valid_interaction' do
44
- expect(pingo.send(:get_device_id)).not_to be_nil
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
- pingo.instance_variable_set(:@partition, pingo.send(:get_partition))
55
+ partition = pingo.send(:request_partition)
56
56
 
57
57
  VCR.use_cassette 'init_client/device_id/invalid_interaction' do
58
- expect(pingo.send(:get_device_id)).to be_nil
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 ".play_sound" do
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
- pingo.instance_variable_set(:@partition, pingo.send(:get_partition))
72
+ partition = pingo.send(:request_partition)
77
73
 
78
74
  VCR.use_cassette 'init_client/device_id/valid_interaction' do
79
- pingo.instance_variable_set(:@device_id, pingo.send(:get_device_id))
75
+ device_ids = pingo.send(:request_device_ids, partition)
80
76
 
81
77
  VCR.use_cassette 'play_sound/valid_interaction' do
82
- response = pingo.send(:play_sound)
83
- expect([response.code, response.response_code]).to include(200)
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
- before do
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
- pingo.instance_variable_set(:@partition, pingo.send(:get_partition))
95
+ partition = pingo.send(:request_partition)
98
96
 
99
97
  VCR.use_cassette 'init_client/device_id/valid_interaction' do
100
- pingo.send(:get_device_id)
98
+ pingo.send(:request_device_ids, partition)
101
99
 
102
100
  VCR.use_cassette 'play_sound/invalid_interaction' do
103
- response = pingo.send(:play_sound)
101
+ responses = pingo.send(:request_sound, partition, device_ids)
104
102
 
105
- # VCR response structure and typhoeus it are differ even
106
- expect([response.code, response.response_code]).to include(500)
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.3
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-10 00:00:00.000000000 Z
11
+ date: 2014-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus