2018/11/30 BE もくもく会vol,1 での登壇資料です。
Netatmo API × RubyͰ ΦϑΟεͷCO2ೱΛSlackʹ௨͢Δ2018/11/30 BE ͘͘ձvol,1Tomoki Ishimaru / @thom_i40
View Slide
ࣗݾհ• Tomoki Ishimaru• GMO AD Marketing Inc.• ϑϩϯτΤϯυ / αʔόʔαΠυ• Իָͱࣸਅ͕͖@thom_i40
ຊ
Netatmo × Ruby ͰΦϑΟεͷCO2ೱΛՄࢹԽ
ͳͥCO2ೱΛՄࢹԽʁ
͖͔͚ͬ
https://www.businessinsider.jp/post-106379
CO2ೱͱਓͷύϑΥʔϚϯε• CO2ೱͷߴ͍ڥͰҙࢥܾఆͳͲͷ ύϑΥʔϚϯε͕Լ͢Δֶज़จ͕ൃද• ްੜ࿑ಇলͱจ෦ՊֶলɺڭҭࢪઃݐஙʹCO2ೱͷج४ΛఆΊ͍ͯΔ• CO2ೱ͕ݸਓͷύϑΥʔϚϯεʹӨڹ͢Δ
CO2ೱͷݟ͑ΔԽ͔Β࢝ΊΑ͏
Ͳ͏ͬͯʁ
Netatmo Weather Station
Netatmo Weather Station• ֎ͷڥΛܭଌ͢ΔϞδϡʔϧ• ؾԹ࣪, ؾѹ, ૽Ի, CO2ೱͳͲΛܭଌ• ෩ྔӍྔΛܭଌ͢ΔՃϞδϡʔϧ• εϚʔτϑΥϯͱ࿈ܞՄೳ• ܭଌσʔλʹΞΫηεͰ͖ΔAPIΛఏڙ
CO2ೱΛSlack௨
Netatmo APIrequire 'net/https' require 'json' require 'uri' token_uri = URI('https://api.netatmo.com/oauth2/token') res = Net::HTTP.post_form( token_uri, grant_type: 'password', client_id: 'xxx', client_secret: 'xxx', username: 'xxx', password: 'xxx', scope: 'read_station' ) access_token = JSON.parse(res.body)['access_token'] api_uri = URI.parse('https://api.netatmo.com/api/getstationsdata') http = Net::HTTP.new(api_uri.host, api_uri.port) http.use_ssl = true req = Net::HTTP::Post.new(api_uri.path) req.set_form_data(access_token: access_token) res = http.request(req) data = JSON.parse(res.body) puts JSON.pretty_generate(data) https://dev.netatmo.com/en-US/resources/technical/samplessdks/tutorials
Ruby͔ΒSlackͷ௨• slack-incoming-webhooks• ߦͷεΫϦϓτͰSlackͷ௨͕Մೳ• Slack APIͷAttachmentsʹରԠhttps://github.com/shoyan/slack-incoming-webhooks
Ruby͔ΒSlackͷ௨https://github.com/shoyan/slack-incoming-webhooks
Google Sheets ग़ྗ• google-drive-ruby• CO2ೱͷؾͷޮՌΛՄࢹԽ͢Δ• άϥϑͷੜڞ༗/ΞΧϯτཧ͕༰қhttps://github.com/gimite/google-drive-ruby
Google Sheets ग़ྗhttps://github.com/gimite/google-drive-ruby
γεςϜߏNetatmoαʔόʔᶃᶄᶅᶆNetatmo Weather StationRuby
IFTTTͰμϝͳͷʁ• ௨͕1࣌ؒ΄ͲΕΔ͜ͱ͕͋ͬͨ• ௨ϑΥʔϚοτͷ੍ޚʹݶք͕͋Δ• ௨ͷ݅͝ͱʹΞϓϨοτͷཧ͕ඞཁ
·ͱΊ• Netatmo APIΛͬͯCO2ೱΛՄࢹԽͨ͠• RubyGemsΛ༻͍ͯ SlackGoogle Sheetsʹग़ྗͨ͠• Slack௨Λ͖͔͚ͬʹؾ͢Δश׳͕͖ɺ CO2ೱ্͕͕Γʹ͍͘ΦϑΟεڥΛ࡞Εͨ
https://techblog.gmo-ap.jp/2018/05/15/ruby_netatmo_api_slack/
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠@thom_i40