Sha256: 17288f20395ea34a9647b228eed1fc5a759997eee8fb961ead3b07a96aae1f4f

Contents?: true

Size: 774 Bytes

Versions: 4

Compression:

Stored size: 774 Bytes

Contents

module Imuze
  class CreateToken < Struct.new(:email, :password)
    require 'uri'
    require 'net/http'
    require 'json'

    def self.call(*args)
      new(*args).call
    end

    def call
      response = http.request(put_request)
      JSON.parse(response.read_body)
    end

    private

    def url
      @url ||= URI('http://joplin.imuze.io/accounts/token')
    end

    def http
      @http ||= Net::HTTP.new(url.host, url.port)
    end

    def put_request
      request = Net::HTTP::Put.new(url)
      request['content-type'] = 'application/json'
      request['cache-control'] = 'no-cache'
      request.body = request_body
      request
    end

    def request_body
      {
        email: email,
        password: password
      }.to_json
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
imuzer-0.0.4 lib/imuze/create_token.rb
imuzer-0.0.3 lib/imuze/create_token.rb
imuzer-0.0.2 lib/imuze/create_token.rb
imuzer-0.0.1 lib/imuze/create_token.rb