class HatenablogPublisher::Photolife

Constants

ENDPOINT

Attributes

client[R]

Public Class Methods

new() click to toggle source
# File lib/hatenablog_publisher/photolife.rb, line 11
def initialize
  @client = HatenablogPublisher::Api.new(ENDPOINT)
end

Public Instance Methods

upload(image) click to toggle source
# File lib/hatenablog_publisher/photolife.rb, line 15
def upload(image)
  body = format_body(image)

  res = with_logging_request(image.title, body) do
    @client.request('/atom/post', body)
  end

  parse_response(res.body)
end

Private Instance Methods

format_body(image, dirname = 'Hatena Blog') click to toggle source
# File lib/hatenablog_publisher/photolife.rb, line 31
    def format_body(image, dirname = 'Hatena Blog')
      body = <<~"XML"
        <entry xmlns="http://purl.org/atom/ns#">
          <title>#{image.title}</title>
          <content mode="base64" type="#{image.mime_type}">
            #{image.content}
          </content>
          <dc:subject>#{dirname}</dc:subject>
        </entry>
      XML

      body
    end
parse_response(response_body) click to toggle source
# File lib/hatenablog_publisher/photolife.rb, line 27
def parse_response(response_body)
  XmlSimple.xml_in(response_body)
end