Class: Libfchat::WebAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/libfchat/webapi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(baseurl = "https://www.f-list.net") ⇒ WebAPI

Returns a new instance of WebAPI.



14
15
16
# File 'lib/libfchat/webapi.rb', line 14

def initialize(baseurl="https://www.f-list.net")
  @baseurl = baseurl
end

Instance Attribute Details

#baseurlObject (readonly)

Returns the value of attribute baseurl.



12
13
14
# File 'lib/libfchat/webapi.rb', line 12

def baseurl
  @baseurl
end

#ticketObject (readonly)

Returns the value of attribute ticket.



11
12
13
# File 'lib/libfchat/webapi.rb', line 11

def ticket
  @ticket
end

Instance Method Details

#bookmark_add(name) ⇒ Object

Bookmarks



58
59
60
61
# File 'lib/libfchat/webapi.rb', line 58

def bookmark_add(name)
  return self.post("/json/api/bookmark-add.php",
                  'name' => name)
end

#bookmark_listObject



63
64
65
# File 'lib/libfchat/webapi.rb', line 63

def bookmark_list()
  return self.get("/json/api/bookmark-list.php")
end

#bookmark_remove(name) ⇒ Object



67
68
69
70
# File 'lib/libfchat/webapi.rb', line 67

def bookmark_remove(name)
  return self.post("/json/api/bookmark-remove.php",
                  'name' => name)
end

#character_data(name) ⇒ Object

Character data



73
74
75
76
# File 'lib/libfchat/webapi.rb', line 73

def character_data(name)
  return self.post("/json/api/character-data.php",
                  'name' => name)
end

#character_listObject



78
79
80
# File 'lib/libfchat/webapi.rb', line 78

def character_list()
  return self.get("/json/api/character-list.php")
end

#friend_listObject

Handling friend requests, friend list data



104
105
106
# File 'lib/libfchat/webapi.rb', line 104

def friend_list()
  return self.get("/json/api/friend-list.php")
end

#friend_remove(source_name, dest_name) ⇒ Object



108
109
110
111
112
# File 'lib/libfchat/webapi.rb', line 108

def friend_remove(source_name, dest_name)
  return self.post("/json/api/friend-remove.php",
                  "source_name" => source_name,
                  "dest_name" => dest_name)
end

#get(endpoint) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/libfchat/webapi.rb', line 31

def get(endpoint)
  uri = URI(@baseurl)
  res = Net::HTTP.get(uri)
  json = MultiJson.load(res.body)
  if json['error'] != ""
    raise json['error']
  end
  return json
end

#get_ticket(account, password) ⇒ Object



41
42
43
44
# File 'lib/libfchat/webapi.rb', line 41

def get_ticket(, password)
  # Deprecated
  return self.getApiTicket(, password)
end

#getApiTicket(account, password) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/libfchat/webapi.rb', line 46

def getApiTicket(, password)
  json = self.post("/json/getApiTicket.php",
                  'account' => ,
                  'password' => password)

  if json['ticket']
    @ticket = json['ticket']
    return json
  end
end

#group_listObject

Misc data



83
84
85
# File 'lib/libfchat/webapi.rb', line 83

def group_list()
  return self.get("/json/api/group-list.php")
end

#ignore_listObject



87
88
89
# File 'lib/libfchat/webapi.rb', line 87

def ignore_list()
  return self.get("/json/api/ignore-list.php")
end

#info_listObject



91
92
93
# File 'lib/libfchat/webapi.rb', line 91

def info_list()
  return self.get("/json/api/info-list.php")
end

#kink_listObject



95
96
97
# File 'lib/libfchat/webapi.rb', line 95

def kink_list()
  return self.get("/json/api/kink-list.php")
end

#mapping_listObject



99
100
101
# File 'lib/libfchat/webapi.rb', line 99

def mapping_list()
  return self.get("/json/api/mapping-list.php")
end

#post(endpoint, params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/libfchat/webapi.rb', line 18

def post(endpoint, params)
  uri = URI("#{@baseurl}#{endpoint}")
  if @ticket
    params['ticket'] = @ticket
  end
  res = Net::HTTP.post_form(uri, params)
  json = MultiJson.load(res.body)
  if json['error'] != ""
    raise json['error']
  end
  return json
end

#request_accept(request_id) ⇒ Object



114
115
116
117
# File 'lib/libfchat/webapi.rb', line 114

def request_accept(request_id)
  return self.post("/json/api/request-accept.php",
                  "request_id" => request_id)
end

#request_cancel(request_id) ⇒ Object



119
120
121
122
# File 'lib/libfchat/webapi.rb', line 119

def request_cancel(request_id)
  return self.post("/json/api/request-cancel.php",
                  "request_id" => request_id)
end

#request_deny(request_id) ⇒ Object



124
125
126
127
# File 'lib/libfchat/webapi.rb', line 124

def request_deny(request_id)
  return self.post("/json/api/request-deny.php",
                  "request_id" => request_id)
end

#request_listObject



129
130
131
# File 'lib/libfchat/webapi.rb', line 129

def request_list()
  return self.get("/json/api/request-list.php")
end

#request_pendingObject



133
134
135
# File 'lib/libfchat/webapi.rb', line 133

def request_pending()
  return self.get("/json/api/request-pending.php")
end

#request_sendObject



137
138
139
# File 'lib/libfchat/webapi.rb', line 137

def request_send()
  return self.get("/json/api/request-send.php")
end