Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Netatmo API × Rubyで
オフィスのCO2濃度をSlackに通知する / Net...

Netatmo API × Rubyで
オフィスのCO2濃度をSlackに通知する / Netatmo API × Ruby × Slack

2018/11/30 BE もくもく会vol,1 での登壇資料です。

Tomoki Ishimaru

November 30, 2018
Tweet

More Decks by Tomoki Ishimaru

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • Tomoki Ishimaru • GMO AD Marketing Inc. •

    ϑϩϯτΤϯυ / αʔόʔαΠυ • Իָͱࣸਅ͕޷͖ @thom_i40
  2. Netatmo Weather Station • ԰಺֎ͷ؀ڥΛܭଌ͢ΔϞδϡʔϧ • ؾԹ΍࣪౓, ؾѹ, ૽Ի, CO2ೱ౓ͳͲΛܭଌ

    • ෩ྔ΍ӍྔΛܭଌ͢Δ௥ՃϞδϡʔϧ • εϚʔτϑΥϯͱ࿈ܞՄೳ • ܭଌσʔλʹΞΫηεͰ͖ΔAPIΛఏڙ
  3. Netatmo API require '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