Sha256: f2bcbee78f070016504519e743c432a80f6aa045e152a48b6ffa571ad2fb64e1

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

require 'uri'
require 'base64'
require 'net/http/persistent'

module ComicWalker
  class Client
    class License
      def initialize(json)
        @json = json
        @http = Net::HTTP::Persistent.new('comic_walker')
      end

      def agreement
        @json['agreement']
      end

      def info_url
        url_prefix + agreement['info_file_name']
      end

      def url_prefix
        agreement['url_prefix']
      end

      CONFIGURATION_PACK_FILENAME = 'configuration_pack.json'

      def configuration_pack_url
        url_prefix + CONFIGURATION_PACK_FILENAME
      end

      def get(url)
        @http.request(URI.parse(url))
      end

      def get_configuration_pack
        JSON.parse(get(configuration_pack_url).body)
      end

      def get_info
        JSON.parse(get(info_url).body)
      end

      def get_jpeg(file)
        get(url_prefix + file + '/0.jpeg').body
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comic_walker-0.3.0 lib/comic_walker/client/license.rb