Sha256: 4485b1b611e95f43b3a7faa8d3f6570b4763d67e9b2c466f22e3584ef55f2f5d
Contents?: true
Size: 1004 Bytes
Versions: 1
Compression:
Stored size: 1004 Bytes
Contents
require 'httparty' require 'active_support/core_ext/class/attribute' require 'active_support/json/decoding' require 'active_support/core_ext/object/to_query' require 'active_support/core_ext/object/blank' require 'active_support/concern' module ChinaAqi module Utility extend ::ActiveSupport::Concern included do include HTTParty attr_accessor :parmas class_attribute :base_uri, :method self.base_uri = URI::HTTP.build(host: 'www.pm25.in') end def get ::ActiveSupport::JSON.decode(HTTParty.get(url).body) end def uri raise NotImplementedError, "Please set value for 'method' class attributes in '#{self.class.name}' class." unless self.class.method method = self.class.method.to_s.include?('/') ? self.class.method : "/querys/#{self.class.method}" self.class.base_uri.path = "/api#{method}.json" self.class.base_uri.query = @parmas.to_query self.class.base_uri end def url uri.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
china_aqi-0.0.5 | lib/china_aqi/utility.rb |