Class: HatenablogPublisher::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/hatenablog_publisher/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Api

Returns a new instance of Api.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hatenablog_publisher/api.rb', line 8

def initialize(site)
  @site = site

  @header = {
    'Accept' => 'application/xml',
    'Content-Type' => 'application/xml'
  }

  consumer = OAuth::Consumer.new(
    ENV['HATENABLOG_CONSUMER_KEY'],
    ENV['HATENABLOG_CONSUMER_SECRET'],
    site: site,
    timeout: 300
  )

  @client = OAuth::AccessToken.new(
    consumer,
    ENV['HATENABLOG_ACCESS_TOKEN'],
    ENV['HATENABLOG_ACCESS_TOKEN_SECRET']
  )
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/hatenablog_publisher/api.rb', line 6

def client
  @client
end

#headerObject (readonly)

Returns the value of attribute header.



6
7
8
# File 'lib/hatenablog_publisher/api.rb', line 6

def header
  @header
end

#siteObject (readonly)

Returns the value of attribute site.



6
7
8
# File 'lib/hatenablog_publisher/api.rb', line 6

def site
  @site
end

Instance Method Details

#request(path, body, method = :post) ⇒ Object



30
31
32
# File 'lib/hatenablog_publisher/api.rb', line 30

def request(path, body, method = :post)
  @client.request(method, path, body, @header)
end