bmw-connected-drive 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 +4 -4
- data/README.md +19 -5
- data/lib/bmw-connected-drive.rb +1 -1
- data/lib/bmw-connected-drive/client.rb +0 -27
- data/lib/bmw-connected-drive/vehicle.rb +45 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 108d392bbfabfc1318188486e87968673eecb31f
|
4
|
+
data.tar.gz: 37d94eb28b2da942f2e154d28f9ec20a3aca4c2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b531ca477e72edcc1a9340bc546095862c18b1c04d76bbea7a1ac6581b9ac1aafb006c73785cae79cd64ae291703e39435e4525e3ca109bb2dcc78838ab8920
|
7
|
+
data.tar.gz: 9108d46243e5a6ed7eda16b3c4a19868ce31b032d8c47e5259d70394dd030e98aceb3df05e2bd2ff682e41a6db488b672c67b4f01fd75935a7ddfdf24326a7f1
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
|
1
|
+
# BMW Connected Drive
|
2
2
|
|
3
|
-
BMW Connected Drive JSON API
|
3
|
+
BMW Connected Drive JSON API wrapper written in ruby
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
I needed a simple wrapper for the BMW Connected Drive JSON API - credits to [Terence Eden](https://github.com/edent) and [Quentin Stafford-Fraser](https://github.com/quentinsf) for their original work documenting the API of the i3 electric car [BMW-i-Remote](https://github.com/edent/BMW-i-Remote)
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -22,9 +28,9 @@ Or install it yourself:
|
|
22
28
|
require 'bmw-connected-drive'
|
23
29
|
|
24
30
|
client = BMWConnectedDrive::Client.new({
|
25
|
-
:auth_basic =>
|
26
|
-
:username =>
|
27
|
-
:password =>
|
31
|
+
:auth_basic => auth_basic,
|
32
|
+
:username => username,
|
33
|
+
:password => password,
|
28
34
|
})
|
29
35
|
|
30
36
|
client.login
|
@@ -36,4 +42,12 @@ vehicle.all_trips
|
|
36
42
|
vehicle.destinations
|
37
43
|
vehicle.charging_profile
|
38
44
|
vehicle.range_map
|
45
|
+
vehicle.execute_service("DOOR_LOCK")
|
39
46
|
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
* Fork the project.
|
51
|
+
* Start a feature/bugfix branch.
|
52
|
+
* Commit and push until you are happy with your contribution.
|
53
|
+
* Submit a pull request
|
data/lib/bmw-connected-drive.rb
CHANGED
@@ -11,37 +11,18 @@ module BMWConnectedDrive
|
|
11
11
|
@username = params[:username]
|
12
12
|
@password = params[:password]
|
13
13
|
@auth_basic = params[:auth_basic]
|
14
|
-
puts @username
|
15
|
-
puts @password
|
16
|
-
puts @auth_basic
|
17
14
|
end
|
18
15
|
|
19
16
|
def access_token=(access_token)
|
20
17
|
@access_token = access_token
|
21
18
|
self.class.headers "User-Agent" => USER_AGENT
|
22
19
|
self.class.headers "Authorization" => "Bearer #{access_token}"
|
23
|
-
#self.class.headers "User-Agent" => USER_AGENT
|
24
|
-
#self.class.headers "Authorization" => "Bearer Zig2rc5cw98vwBNJhLZ3AZ4Fx6L9Qecp"
|
25
20
|
end
|
26
21
|
|
27
22
|
def expires_in=(seconds)
|
28
23
|
@expires_in = seconds.to_f
|
29
24
|
end
|
30
25
|
|
31
|
-
def created_at=(timestamp)
|
32
|
-
@created_at = Time.at(timestamp.to_f).to_datetime
|
33
|
-
end
|
34
|
-
|
35
|
-
def expired_at
|
36
|
-
return nil unless defined?(@created_at)
|
37
|
-
(@created_at.to_time + @expires_in.to_f).to_datetime
|
38
|
-
end
|
39
|
-
|
40
|
-
def expired?
|
41
|
-
return true unless defined?(@created_at)
|
42
|
-
expired_at <= DateTime.now
|
43
|
-
end
|
44
|
-
|
45
26
|
def login
|
46
27
|
response = self.class.post(
|
47
28
|
"/oauth/token",
|
@@ -57,23 +38,15 @@ module BMWConnectedDrive
|
|
57
38
|
"User-Agent" => USER_AGENT
|
58
39
|
}
|
59
40
|
)
|
60
|
-
|
61
|
-
puts response
|
62
|
-
|
63
41
|
self.expires_in = response["expires_in"]
|
64
|
-
#self.created_at = response["created_at"]
|
65
42
|
self.access_token = response["access_token"]
|
66
43
|
end
|
67
44
|
|
68
45
|
def call(path)
|
69
|
-
self.class.headers "User-Agent" => USER_AGENT
|
70
|
-
self.class.headers "Authorization" => "Bearer Zig2rc5cw98vwBNJhLZ3AZ4Fx6L9Qecp"
|
71
46
|
self.class.get(path)
|
72
47
|
end
|
73
48
|
|
74
49
|
def vehicles
|
75
|
-
#self.class.headers "User-Agent" => USER_AGENT
|
76
|
-
#self.class.headers "Authorization" => "Bearer Zig2rc5cw98vwBNJhLZ3AZ4Fx6L9Qecp"
|
77
50
|
self.class.get("/v1/user/vehicles/")["vehicles"].map { |vehicle| Vehicle.new(self.class, vehicle) }
|
78
51
|
end
|
79
52
|
end
|
@@ -1,5 +1,29 @@
|
|
1
1
|
module BMWConnectedDrive
|
2
2
|
class Vehicle
|
3
|
+
SERVICES = [
|
4
|
+
"DOOR_LOCK",
|
5
|
+
"DOOR_UNLOCK",
|
6
|
+
"CHARGE_NOW",
|
7
|
+
"CHARGING_CONTROL",
|
8
|
+
"CLIMATE_CONTROL",
|
9
|
+
"CLIMATE_NOW",
|
10
|
+
"DOOR_LOCK",
|
11
|
+
"DOOR_UNLOCK",
|
12
|
+
"GET_ALL_IMAGES",
|
13
|
+
"GET_PASSWORD_RESET_INFO",
|
14
|
+
"GET_VEHICLES",
|
15
|
+
"GET_VEHICLE_IMAGE",
|
16
|
+
"GET_VEHICLE_STATUS",
|
17
|
+
"HORN_BLOW",
|
18
|
+
"LIGHT_FLASH",
|
19
|
+
"LOCAL_SEARCH",
|
20
|
+
"LOCAL_SEARCH_SUGGESTIONS",
|
21
|
+
"LOGIN",
|
22
|
+
"LOGOUT",
|
23
|
+
"SEND_POI_TO_CAR",
|
24
|
+
"VEHICLE_FINDER"
|
25
|
+
]
|
26
|
+
|
3
27
|
attr_reader :api, :vehicle
|
4
28
|
|
5
29
|
def initialize(api, vehicle)
|
@@ -31,5 +55,26 @@ module BMWConnectedDrive
|
|
31
55
|
api.get("/v1/user/vehicles/#{vehicle['vin']}/rangemap")["rangemap"]
|
32
56
|
end
|
33
57
|
|
58
|
+
def execute_service(service_type, secret_knowledge=nil)
|
59
|
+
responses = []
|
60
|
+
if SERVICES.include? service_type
|
61
|
+
response = api.post(
|
62
|
+
"/v1/user/vehicles/#{vehicle['vin']}/executeService",
|
63
|
+
body: {
|
64
|
+
"serviceType" => service_type,
|
65
|
+
"secretKnowledge" => secret_knowledge
|
66
|
+
}
|
67
|
+
)
|
68
|
+
status = response["executionStatus"]["status"]
|
69
|
+
responses << response["executionStatus"]
|
70
|
+
while ["INITIATED","PENDING"].include? status do
|
71
|
+
response = api.get("/v1/user/vehicles/#{vehicle['vin']}/serviceExecutionStatus?serviceType=#{service_type}")
|
72
|
+
status = response["executionStatus"]["status"]
|
73
|
+
responses << response["executionStatus"]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
responses
|
77
|
+
end
|
78
|
+
|
34
79
|
end
|
35
80
|
end
|