kakaxi 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4b057764ba0dfdc5483338bbe4dee6bd858e1fb6
4
- data.tar.gz: 1cd5734058abb795e992c1e54186244fd390fd09
2
+ SHA256:
3
+ metadata.gz: 057a9bf5c0acb652d11d49e14f9427979b263bff2ea9c3a49c58a252f38b0d3e
4
+ data.tar.gz: 16b2e1e12a56e114987786401b6a7f6ed7bd6b2f089bb4315572bfb70477a8ee
5
5
  SHA512:
6
- metadata.gz: 4dd29982e460d008a6aaaad81b5ea690f062d47e1684eeb808a57f780319b126c57481ec572f28ada86811143111fc45fb7924e92929e1196b509a706fabb3cd
7
- data.tar.gz: ec080335be6505796f2b338f4117de5773db93970c6c5e3286347f6ba64d16a9b263c6d0e78a3a2334ff73c7f0fbe33762234305c2ccb23e1e656f374019c56e
6
+ metadata.gz: bf01338504fcd09f811ed8368c8a8455e16bcb1002d63bdf81f145541864b1b563f549be7d637a8bbb881e2911b8b04f176ffcd946f163c6b06eaed9a18ea95f
7
+ data.tar.gz: a36fb054b48d1587e2e29a99b696c7b02b4de2d89a9a95128ada2464293abd7fe91f0a65a5881550c16b966b74f61cb50848b76fef97c8b4f33df9c2e0c891c1
data/kakaxi.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'kakaxi'
6
- s.version = '0.0.2'
6
+ s.version = '0.0.3'
7
7
  s.date = '2017-09-10'
8
8
  s.summary = 'Library for calling kakaxi api by ruby'
9
9
  s.description = 'Make it easy to use Kakaxi API by ruby'
@@ -1,4 +1,4 @@
1
- class InvalidCredentials < StandardError
1
+ class InvalidCredentialsError < StandardError
2
2
  def initialize(email, password, msg='email: %s, or password: %s is invalid')
3
3
  super(msg % [email, password])
4
4
  end
data/lib/kakaxi/client.rb CHANGED
@@ -6,7 +6,7 @@ require 'net/https'
6
6
  module Kakaxi
7
7
  class Client
8
8
  COMMON_HEADER = { 'Content-Type' => 'application/json' }
9
- BASE_URL = 'https://kakaxi-data.me/api/v1/'
9
+ BASE_URL = 'http://localhost:8080/api/v1/'
10
10
  attr_reader :current_device, :temps, :temp_data, :token,
11
11
  :farm, :devices, :humidities, :timelapses, :solar_radiations,
12
12
  :rainfalls, :interval_photos, :interval_photo_data
@@ -14,10 +14,6 @@ module Kakaxi
14
14
  def initialize(email, password)
15
15
  @email = email
16
16
  @password = password
17
- @token = get_token
18
- @farm = get_farm
19
- @devices = get_devices
20
- @current_device = @devices[0]
21
17
  end
22
18
 
23
19
  def set_current_device(index: 0, id: nil, name: nil)
@@ -26,8 +22,21 @@ module Kakaxi
26
22
  @current_device = @devices.find { |device| device.name == name } unless name.nil?
27
23
  end
28
24
 
29
- def load_temps(days: 5, unit: 'celsius')
30
- uri = URI.parse(BASE_URL + "kakaxi_devices/#{current_device.id}/indicators/temperature?days=#{days}&unit=#{unit}")
25
+ def load_token
26
+ @token = get_token
27
+ end
28
+
29
+ def load_farm
30
+ @farm = get_farm
31
+ end
32
+
33
+ def load_devices
34
+ @devices = get_devices
35
+ @current_device = @devices[0]
36
+ end
37
+
38
+ def load_temps(days: 5, unit: 'celsius', start_date: Date.today - 7, end_date: Date.today)
39
+ uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/temperature?start_date=#{start_date}&end_date=#{end_date}&unit=#{unit}")
31
40
  temps = get(uri)['data']
32
41
  Struct.new('TempMetaData', :size, :unit, :device_id)
33
42
  @temps = temps.map do |temp|
@@ -36,8 +45,8 @@ module Kakaxi
36
45
  @temp_data = Struct::TempMetaData.new(@temps.length, unit, @current_device.id)
37
46
  end
38
47
 
39
- def load_humidities(days: 5)
40
- uri = URI.parse(BASE_URL + "kakaxi_devices/#{current_device.id}/indicators/humidity?days=#{days}")
48
+ def load_humidities(days: 5, start_date: Date.today - 7, end_date: Date.today)
49
+ uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/humidity?start_date=#{start_date}&end_date=#{end_date}")
41
50
  humidities = get(uri)['data']
42
51
  Struct.new('HumidityMetaData', :size, :device_id)
43
52
  @humidities = humidities.map do |humidity|
@@ -51,8 +60,8 @@ module Kakaxi
51
60
  @humidity_data = Struct::HumidityMetaData.new(@humidities.length, @current_device.id)
52
61
  end
53
62
 
54
- def load_solar_radiations(days: 5, unit: 'watt')
55
- uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/solar_radiation?days=#{days}&unit=#{unit}")
63
+ def load_solar_radiations(start_date: Datetime.today - 5, end_date: Datetime.today)
64
+ uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/solar_radiation?start_date=#{start_date}&end_date=#{end_date}&unit=watt")
56
65
  solar_radiations = get(uri)['data']
57
66
  Struct.new('SolarRadiationMetaData', :size, :unit, :device_id)
58
67
  @solar_radiations = solar_radiations.map do |solar_radiation|
@@ -62,21 +71,21 @@ module Kakaxi
62
71
  interpolation: solar_radiation['interpolation']
63
72
  )
64
73
  end
65
- @solar_radiation_data = Struct::SolarRadiationMetaData.new(@solar_radiations.length, unit, @current_device.id)
74
+ @solar_radiation_data = Struct::SolarRadiationMetaData.new(@solar_radiations.length, 'watt', @current_device.id)
66
75
  end
67
76
 
68
- def load_rainfalls(days: 5, unit: 'inch')
69
- uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/rainfall?days=#{days}&unit=#{unit}")
77
+ def load_rainfalls(days: 5, start_date: Date.today - 7, end_date: Date.today)
78
+ uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/rainfall?start_date=#{start_date}&end_date=#{end_date}&unit=inch")
70
79
  rainfalls = get(uri)['data']
71
80
  Struct.new('RainfallMetaData', :size, :unit, :device_id)
72
81
  @rainfalls = rainfalls.map do |rainfall|
73
82
  Kakaxi::Data::Rainfall.new(value: rainfall['amount'], recorded_at: rainfall['recorded_at'], interpolation: rainfall['interpolation'])
74
83
  end
75
- @rainfall_data = Struct::RainfallMetaData.new(@rainfalls.length, unit, @current_device.id)
84
+ @rainfall_data = Struct::RainfallMetaData.new(@rainfalls.length, 'inch', @current_device.id)
76
85
  end
77
86
 
78
- def load_timelapses(days: 5)
79
- uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/timelapse?days=#{days}")
87
+ def load_timelapses(days: 5, start_date: Date.today - 7, end_date: Date.today)
88
+ uri = URI.parse(BASE_URL + "kakaxi_devices/#{@current_device.id}/indicators/timelapse?start_date=#{start_date}&end_date=#{end_date}")
80
89
  timelapses = get(uri)['data']
81
90
  Struct.new('TimelapseMetaData', :size, :device_id)
82
91
  @timelapses = timelapses.map do |timelapse|
@@ -113,7 +122,7 @@ module Kakaxi
113
122
  uri = URI.parse(BASE_URL + 'oauth/token')
114
123
  params = { username: @email, password: @password, grant_type: 'password', scope: 'all' }
115
124
  response = post(uri, params)
116
- raise InvalidCredentials.new(@email, @password) if response.code == '404'
125
+ raise InvalidCredentialsError.new(@email, @password) if response.code == '404'
117
126
  JSON.parse(response.body)['access_token']
118
127
  end
119
128
 
@@ -148,12 +157,12 @@ module Kakaxi
148
157
 
149
158
  def https(uri)
150
159
  https = Net::HTTP.new(uri.host, uri.port)
151
- https.use_ssl = true
160
+ # https.use_ssl = true
152
161
  https
153
162
  end
154
163
 
155
164
  def indicator_uri(device_id, indicator, days, unit)
156
- URI.parse(BASE_URL + "kakaxi_devices/#{device_id}/indicators/#{indicator}?days=#{days}")
165
+ URI.parse(BASE_URL + "kakaxi_devices/#{device_id}/indicators/#{indicator}?start_date=#{start_date}&end_date=#{end_date}")
157
166
  end
158
167
  end
159
168
  end
@@ -1,5 +1,5 @@
1
1
  module Kakaxi
2
- class Temperature
2
+ class IntervalPhoto
3
3
  attr_reader :id, :url, :taken_at
4
4
 
5
5
  def initialize(id: nil, url: nil, taken_at: nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kakaxi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naggi Goishi
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.6.13
56
+ rubygems_version: 2.7.4
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: Library for calling kakaxi api by ruby