lib/ika3/schedule.rb in ika3-0.2.1 vs lib/ika3/schedule.rb in ika3-0.3.0
- old
+ new
@@ -1,56 +1,63 @@
class Hash
def method_missing(name)
- return self[name].extend Hash if key? name
+ return self[name] if key? name
each { |k, v| return v if k.to_s.to_sym == name }
super.method_missing(name)
end
end
module Ika3
class Schedule
- class << self
- modes = ["regular", "bankara_challenge", "bankara_open", "x"]
- schedules = ["now", "next"]
+ def initialize(contact)
+ @contact = contact
+ end
- schedules.each do |schedule|
- modes.each do |mode|
- define_method("#{mode}_#{schedule}".to_sym) do
- return instance_variable_get("@#{mode}_#{schedule}_obj") if instance_variable_defined?("@#{mode}_#{schedule}_obj")
+ modes = ["regular", "bankara_challenge", "bankara_open", "x"]
+ schedules = ["now", "next"]
- instance_variable_set("@#{mode}_#{schedule}_obj", send_request(:get, "/api/#{mode.dasherize}/#{schedule}").body.results[0])
- end
- end
+ schedules.each do |schedule|
+ modes.each do |mode|
+ define_method("#{mode}_#{schedule}".to_sym) do
+ return instance_variable_get("@#{mode}_#{schedule}_obj") if instance_variable_defined?("@#{mode}_#{schedule}_obj")
- define_method("salmon_run_#{schedule}".to_sym) do
- return instance_variable_get("@salmon_run_#{schedule}_obj") if instance_variable_defined?("@salmon_run_#{schedule}_obj")
-
- instance_variable_set("@salmon_run_#{schedule}_obj", send_request(:get, "/api/coop-grouping/#{schedule}").body.results[0])
+ instance_variable_set("@#{mode}_#{schedule}_obj", send_request(:get, "/api/#{mode.dasherize}/#{schedule}").body.results[0])
end
end
- private
+ define_method("salmon_run_#{schedule}".to_sym) do
+ return instance_variable_get("@salmon_run_#{schedule}_obj") if instance_variable_defined?("@salmon_run_#{schedule}_obj")
- def send_request(method, path, params = nil, headers = nil)
- response = splat3_connection.send(method, path, params, headers)
- Ika3::Response.new(response)
+ instance_variable_set("@salmon_run_#{schedule}_obj", send_request(:get, "/api/coop-grouping/#{schedule}").body.results[0])
end
+ end
- def api_url
- "https://spla3.yuu26.com/"
- end
+ private
- def splat3_connection
- @splat3_connection ||= Faraday::new(faraday_options) do |c|
- c.request :json
- c.response :json
- c.adapter Faraday.default_adapter
- end
- end
+ def send_request(method, path)
+ response = splat3_connection.send(method, path)
+ Ika3::Response.new(response)
+ end
- def faraday_options
- { url: api_url }
+ def api_url
+ "https://spla3.yuu26.com/"
+ end
+
+ def splat3_connection
+ @splat3_connection ||= Faraday::new(faraday_options) do |c|
+ c.request :json
+ c.response :json
+ c.adapter Faraday.default_adapter
end
+ end
+
+ def faraday_options
+ {
+ url: api_url,
+ headers: {
+ 'User-Agent': "Ika3Gem/#{Ika3::VERSION}(#{@contact})"
+ }
+ }
end
end
end