class Esayari::Client

Public Class Methods

new(token) click to toggle source
# File lib/esayari/client.rb, line 3
def initialize(token)
  endpoint = 'https://api.esa.io'

  url = URI.parse(endpoint)
  @http = Net::HTTP.new(url.host, url.port)
  @http.use_ssl = true
  @headers = {
    "Content-Type"  => "application/json",
    "Authorization" => "Bearer #{token}",
  }
end

Public Instance Methods

create_post(team_path, name, body, tags, category, wip: true) click to toggle source

docs.esa.io/posts/102#POST%20/v1/teams/:team_name/posts

# File lib/esayari/client.rb, line 16
def create_post(team_path, name, body, tags, category, wip: true)
  path = "/v1/teams/#{team_path}/posts"

  params = {
    post: {
      name: name,
      body_md: body,
      tags: tags,
      category: category,
      wip: wip,
    }
  }

  @http.post(path, JSON.generate(params), @headers)
end
create_post_with_template(team_path, tags, category, template_post_id: nil, wip: true) click to toggle source

create_postとほぼ一緒だが、仕様でnameがrequireじゃなくなるっぽかったので、 コード上で分岐させられるけど明示的にメソッドを分けてしまった。

# File lib/esayari/client.rb, line 34
def create_post_with_template(team_path, tags, category, template_post_id: nil, wip: true)
  path = "/v1/teams/#{team_path}/posts"

  params = {
    post: {
      tags: tags,
      category: category,
      template_post_id: template_post_id,
      wip: wip,
    }
  }

  @http.post(path, JSON.generate(params), @headers)
end