Class: HatenablogPublisher::Entry

Inherits:
Object
  • Object
show all
Includes:
RequestLogger
Defined in:
lib/hatenablog_publisher/entry.rb

Constant Summary collapse

ENDPOINT =
'https://blog.hatena.ne.jp'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestLogger

#log, #with_logging_request

Constructor Details

#initialize(context, options) ⇒ Entry

Returns a new instance of Entry.



12
13
14
15
16
# File 'lib/hatenablog_publisher/entry.rb', line 12

def initialize(context, options)
  @client = HatenablogPublisher::Api.new(ENDPOINT)
  @context = context
  @options = options
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/hatenablog_publisher/entry.rb', line 8

def client
  @client
end

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/hatenablog_publisher/entry.rb', line 8

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/hatenablog_publisher/entry.rb', line 8

def options
  @options
end

Instance Method Details

#post_entry(body) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hatenablog_publisher/entry.rb', line 18

def post_entry(body)
  request_xml = format_request(body)
  basename = File.basename(@options.filename)

  res = with_logging_request(basename, request_xml) do
    method = @context.hatena.dig(:id) ? :put : :post
    @client.request(api_url, request_xml, method)
  end

  parse_response(res.body)
end