Module: WeebSh::API::Toph

Defined in:
lib/weeb/api/toph.rb

Overview

API endpoints for Toph

Constant Summary collapse

BASE =
'/images'.freeze

Class Method Summary collapse

Class Method Details

.add_tags_to_image(interface, id, tags) ⇒ Object


90
91
92
93
94
95
96
97
98
99
100
# File 'lib/weeb/api/toph.rb', line 90

def add_tags_to_image(interface, id, tags)
  WeebSh::API.request(
    :post,
    "#{interface.api_url}#{BASE}/info/#{id}",
    { tags: tags }.to_json,
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.image(interface, id) ⇒ Object


79
80
81
82
83
84
85
86
87
88
# File 'lib/weeb/api/toph.rb', line 79

def image(interface, id)
  WeebSh::API.request(
    :get,
    "#{interface.api_url}#{BASE}/info/#{id}",
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.list(interface, query) ⇒ Object


125
126
127
128
129
130
131
132
133
134
# File 'lib/weeb/api/toph.rb', line 125

def list(interface, query)
  WeebSh::API.request(
    :get,
    "#{interface.api_url}#{BASE}/list?#{URI.encode_www_form(query)}",
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.list_user(interface, id, query) ⇒ Object


136
137
138
139
140
141
142
143
144
145
# File 'lib/weeb/api/toph.rb', line 136

def list_user(interface, id, query)
  WeebSh::API.request(
    :get,
    "#{interface.api_url}#{BASE}/list/#{id}?#{URI.encode_www_form(query)}",
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.random(interface, query) ⇒ Object


68
69
70
71
72
73
74
75
76
77
# File 'lib/weeb/api/toph.rb', line 68

def random(interface, query)
  WeebSh::API.request(
    :get,
    "#{interface.api_url}#{BASE}/random?#{URI.encode_www_form(query)}",
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.remove_image(interface, id) ⇒ Object


114
115
116
117
118
119
120
121
122
123
# File 'lib/weeb/api/toph.rb', line 114

def remove_image(interface, id)
  WeebSh::API.request(
    :delete,
    "#{interface.api_url}#{BASE}/info/#{id}",
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.remove_tags_to_image(interface, id, tags) ⇒ Object


102
103
104
105
106
107
108
109
110
111
112
# File 'lib/weeb/api/toph.rb', line 102

def remove_tags_to_image(interface, id, tags)
  WeebSh::API.request(
    :delete,
    "#{interface.api_url}#{BASE}/info/#{id}",
    { tags: tags }.to_json,
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.tags(interface, query) ⇒ Object


57
58
59
60
61
62
63
64
65
66
# File 'lib/weeb/api/toph.rb', line 57

def tags(interface, query)
  WeebSh::API.request(
    :get,
    "#{interface.api_url}#{BASE}/tags?#{URI.encode_www_form(query)}",
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.types(interface, query) ⇒ Object


46
47
48
49
50
51
52
53
54
55
# File 'lib/weeb/api/toph.rb', line 46

def types(interface, query)
  WeebSh::API.request(
    :get,
    "#{interface.api_url}#{BASE}/types?#{URI.encode_www_form(query)}",
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end

.upload(interface, resource, type, hidden, tags, nsfw, source) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/weeb/api/toph.rb', line 12

def upload(interface, resource, type, hidden, tags, nsfw, source)
  resource.is_a?(File) ? WeebSh::API.request(
    :post,
    "#{interface.api_url}#{BASE}/upload",
    {
      'file'.to_sym => resource,
      'baseType'.to_sym => type,
      'hidden'.to_sym => hidden,
      'tags'.to_sym => tags,
      'nsfw'.to_sym => nsfw,
      'source'.to_sym => source
    },
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  ) : WeebSh::API.request(
    :post,
    "#{interface.api_url}#{BASE}/upload",
    {
      url: resource,
      baseType: type,
      hidden: hidden,
      tags: tags,
      nsfw: nsfw,
      source: source
    }.to_json,
    {
      Authorization: interface.auth,
      'User-Agent': interface.user_agent
    }
  )
end