Class: Fanfeedrb::Fanfeedr
- Inherits:
-
Object
- Object
- Fanfeedrb::Fanfeedr
show all
- Defined in:
- lib/fanfeedrb/fanfeedr.rb,
lib/fanfeedrb/fanfeedr/geo.rb,
lib/fanfeedrb/fanfeedr/team.rb,
lib/fanfeedrb/fanfeedr/event.rb,
lib/fanfeedrb/fanfeedr/league.rb,
lib/fanfeedrb/fanfeedr/content.rb,
lib/fanfeedrb/fanfeedr/conference.rb
Defined Under Namespace
Classes: Abstract, Conference, Error, Event, Geo, League, Team
Constant Summary
collapse
- ADDRESS =
/silver/api/leagues/20f0857f-3c43-5f50-acfc-879f838ee853/events/4dd1704b-a712-511c-b947-8c8f03ea3200?api_key=vbxctn5sn8x7jz644evkrhtc
"ffapi.fanfeedr.com"
- BASE_PATH =
"/#{Fanfeedrb.config['api_plan']}/api/"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(token, plan, ssl = false) ⇒ Fanfeedr
Returns a new instance of Fanfeedr.
14
15
16
17
18
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 14
def initialize(token,plan, ssl = false)
@token = token
@plan = plan
@ssl = ssl
end
|
Instance Attribute Details
#plan ⇒ Object
Returns the value of attribute plan.
12
13
14
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 12
def plan
@plan
end
|
#token ⇒ Object
Returns the value of attribute token.
12
13
14
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 12
def token
@token
end
|
Instance Method Details
#get_json(path) ⇒ Object
61
62
63
64
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 61
def get_json(path)
p path
request_json(:get, path)
end
|
#http ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 23
def http
unless @http
if ssl?
require 'net/https'
@http = Net::HTTP.new(ADDRESS, Net::HTTP.https_default_port)
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@http.use_ssl = true
else
require 'net/http'
@http = Net::HTTP.new(ADDRESS)
end
end
@http
end
|
#league(id) ⇒ Object
66
67
68
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 66
def league(id)
League.new(self,get_json("/leagues/#{id}"))
end
|
#request(method, path, *args) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 38
def request(method, path, *args)
= {
"Accept" => "application/json",
"Content-type" => "application/json"
}
http klass = Net::HTTP.const_get(method.to_s.capitalize)
p klass
path << "?api_key=#{CGI.escape(@token)}"
p path
http.request(klass.new("#{BASE_PATH}#{path}", ), *args)
end
|
#request_json(method, path, *args) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 51
def request_json(method, path, *args)
response = request(method,path,*args)
raise response.inspect if response["Content-type"].split(/; */).first != "application/json"
hash = Crack::JSON.parse(response.body)
if hash.class == Hash && hash["message"] && (response.code.to_i >= 400 || hash["success"] == "false")
raise Error, hash["message"], caller
end
hash
end
|
#ssl? ⇒ Boolean
20
21
22
|
# File 'lib/fanfeedrb/fanfeedr.rb', line 20
def ssl?
@ssl
end
|