weeb 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9d900a7f70e3ae873dbb55e26a6f24feeef6981f
4
- data.tar.gz: 5af3916cb1ded4612981e94edb9e99a46763e029
2
+ SHA256:
3
+ metadata.gz: c9915938edda957206ae587f49a1dd536f113558ca866dffc10133dd2a4d2f43
4
+ data.tar.gz: 99cac3b5e83da4655a2539d115a1c5e921189e7d845c2f9c654dc5c78c4e2372
5
5
  SHA512:
6
- metadata.gz: 5a596fd7ec93ff32b3182a89439a5576b7f82192c70c87d0515ecd6719a87a7f000ff7f9f47524c2afc883c27c8a6236c89d8aba4ae5efa49e58bcc323bb0042
7
- data.tar.gz: f6e6029ed3a7a0cf1d7e63fb556356494ccd81196692cc5208e78bf90583e2256da9c18b1aa419d1d7a2ba29b0047c507816e5f7a622c467c1a8ee0ffa993892
6
+ metadata.gz: 85d0d2efebbc6747a5e3f93c57e29411aa148e99385a50e82849f68d5dcafb93ae31abc6067f2b100b626710cfe323dccf7e0245dce36b2036b0f9556f91fde4
7
+ data.tar.gz: dfeb4ac2515f3c2803349e9afcb32a96ab43d3adbf0d74490645e6639599174543dae06c0e3cab68caede164a08241baf7e9c7608f5355184bf0219977cc11db
@@ -1 +1 @@
1
- require 'weeb/interfaces/client'
1
+ require 'weeb/interfaces/client'
@@ -5,8 +5,8 @@ require 'json'
5
5
  require 'rest-client'
6
6
 
7
7
  module WeebSh
8
+ # Main API functions
8
9
  module API
9
-
10
10
  module_function
11
11
 
12
12
  def request(type, *attributes)
@@ -21,7 +21,7 @@ module WeebSh
21
21
  rescue RestClient::BadRequest => e
22
22
  json = parse_json(e.response)
23
23
  if json.is_a?(Hash)
24
- raise WeebSh::Err::InvalidMIME, json['message'] if json['message'].start_with? 'The mimetype' and json['message'].end_with? 'is not supported'
24
+ raise WeebSh::Err::InvalidMIME, json['message'] if json['message'].start_with? 'The mimetype'
25
25
  raise WeebSh::Err::TagExists, json['message'] if json['message'] == 'Tags existed already or had no content'
26
26
  raise WeebSh::Err::ImagePrivate, json['message'] if json['message'] == 'This image is private'
27
27
  raise WeebSh::Err::InvalidImage, json['message'] if json['message'] == 'No image found for your query'
@@ -3,11 +3,10 @@ require 'uri'
3
3
 
4
4
  module WeebSh
5
5
  module API
6
+ # API endpoints for Korra
6
7
  module Korra
7
8
  BASE = '/auto-image'.freeze
8
-
9
- module_function
10
-
9
+ # module_function
11
10
  end
12
11
  end
13
- end
12
+ end
@@ -3,11 +3,10 @@ require 'uri'
3
3
 
4
4
  module WeebSh
5
5
  module API
6
+ # API endpoints for Shimakaze
6
7
  module Shimakaze
7
8
  BASE = '/reputation'.freeze
8
-
9
- module_function
10
-
9
+ # module_function
11
10
  end
12
11
  end
13
- end
12
+ end
@@ -3,11 +3,10 @@ require 'uri'
3
3
 
4
4
  module WeebSh
5
5
  module API
6
+ # API endpoints for Tama
6
7
  module Tama
7
8
  BASE = '/settings'.freeze
8
-
9
- module_function
10
-
9
+ # module_function
11
10
  end
12
11
  end
13
- end
12
+ end
@@ -3,15 +3,16 @@ require 'uri'
3
3
 
4
4
  module WeebSh
5
5
  module API
6
+ # API endpoints for Toph
6
7
  module Toph
7
8
  BASE = '/images'.freeze
8
9
 
9
10
  module_function
10
11
 
11
- def upload(i, resource, type, hidden, tags, nsfw, source)
12
+ def upload(interface, resource, type, hidden, tags, nsfw, source)
12
13
  resource.is_a?(File) ? WeebSh::API.request(
13
14
  :post,
14
- "#{i.api_url}#{BASE}/upload",
15
+ "#{interface.api_url}#{BASE}/upload",
15
16
  {
16
17
  'file'.to_sym => resource,
17
18
  'baseType'.to_sym => type,
@@ -21,12 +22,12 @@ module WeebSh
21
22
  'source'.to_sym => source
22
23
  },
23
24
  {
24
- Authorization: i.auth,
25
- 'User-Agent': i.user_agent
25
+ Authorization: interface.auth,
26
+ 'User-Agent': interface.user_agent
26
27
  }
27
28
  ) : WeebSh::API.request(
28
29
  :post,
29
- "#{i.api_url}#{BASE}/upload",
30
+ "#{interface.api_url}#{BASE}/upload",
30
31
  {
31
32
  url: resource,
32
33
  baseType: type,
@@ -36,112 +37,112 @@ module WeebSh
36
37
  source: source
37
38
  }.to_json,
38
39
  {
39
- Authorization: i.auth,
40
- 'User-Agent': i.user_agent
40
+ Authorization: interface.auth,
41
+ 'User-Agent': interface.user_agent
41
42
  }
42
43
  )
43
44
  end
44
45
 
45
- def types(i, query)
46
+ def types(interface, query)
46
47
  WeebSh::API.request(
47
48
  :get,
48
- "#{i.api_url}#{BASE}/types?#{URI.encode_www_form(query)}",
49
+ "#{interface.api_url}#{BASE}/types?#{URI.encode_www_form(query)}",
49
50
  {
50
- Authorization: i.auth,
51
- 'User-Agent': i.user_agent
51
+ Authorization: interface.auth,
52
+ 'User-Agent': interface.user_agent
52
53
  }
53
54
  )
54
55
  end
55
56
 
56
- def tags(i, query)
57
+ def tags(interface, query)
57
58
  WeebSh::API.request(
58
59
  :get,
59
- "#{i.api_url}#{BASE}/tags?#{URI.encode_www_form(query)}",
60
+ "#{interface.api_url}#{BASE}/tags?#{URI.encode_www_form(query)}",
60
61
  {
61
- Authorization: i.auth,
62
- 'User-Agent': i.user_agent
62
+ Authorization: interface.auth,
63
+ 'User-Agent': interface.user_agent
63
64
  }
64
65
  )
65
66
  end
66
67
 
67
- def random(i, query)
68
+ def random(interface, query)
68
69
  WeebSh::API.request(
69
70
  :get,
70
- "#{i.api_url}#{BASE}/random?#{URI.encode_www_form(query)}",
71
+ "#{interface.api_url}#{BASE}/random?#{URI.encode_www_form(query)}",
71
72
  {
72
- Authorization: i.auth,
73
- 'User-Agent': i.user_agent
73
+ Authorization: interface.auth,
74
+ 'User-Agent': interface.user_agent
74
75
  }
75
76
  )
76
77
  end
77
78
 
78
- def image(i, id)
79
+ def image(interface, id)
79
80
  WeebSh::API.request(
80
81
  :get,
81
- "#{i.api_url}#{BASE}/info/#{id}",
82
+ "#{interface.api_url}#{BASE}/info/#{id}",
82
83
  {
83
- Authorization: i.auth,
84
- 'User-Agent': i.user_agent
84
+ Authorization: interface.auth,
85
+ 'User-Agent': interface.user_agent
85
86
  }
86
87
  )
87
88
  end
88
89
 
89
- def add_tags_to_image(i, id, tags)
90
+ def add_tags_to_image(interface, id, tags)
90
91
  WeebSh::API.request(
91
92
  :post,
92
- "#{i.api_url}#{BASE}/info/#{id}",
93
+ "#{interface.api_url}#{BASE}/info/#{id}",
93
94
  { tags: tags }.to_json,
94
95
  {
95
- Authorization: i.auth,
96
- 'User-Agent': i.user_agent
96
+ Authorization: interface.auth,
97
+ 'User-Agent': interface.user_agent
97
98
  }
98
99
  )
99
100
  end
100
101
 
101
- def remove_tags_to_image(i, id, tags)
102
+ def remove_tags_to_image(interface, id, tags)
102
103
  WeebSh::API.request(
103
104
  :delete,
104
- "#{i.api_url}#{BASE}/info/#{id}",
105
+ "#{interface.api_url}#{BASE}/info/#{id}",
105
106
  { tags: tags }.to_json,
106
107
  {
107
- Authorization: i.auth,
108
- 'User-Agent': i.user_agent
108
+ Authorization: interface.auth,
109
+ 'User-Agent': interface.user_agent
109
110
  }
110
111
  )
111
112
  end
112
113
 
113
- def remove_image(i, id)
114
+ def remove_image(interface, id)
114
115
  WeebSh::API.request(
115
116
  :delete,
116
- "#{i.api_url}#{BASE}/info/#{id}",
117
+ "#{interface.api_url}#{BASE}/info/#{id}",
117
118
  {
118
- Authorization: i.auth,
119
- 'User-Agent': i.user_agent
119
+ Authorization: interface.auth,
120
+ 'User-Agent': interface.user_agent
120
121
  }
121
122
  )
122
123
  end
123
124
 
124
- def list(i, query)
125
+ def list(interface, query)
125
126
  WeebSh::API.request(
126
127
  :get,
127
- "#{i.api_url}#{BASE}/list?#{URI.encode_www_form(query)}",
128
+ "#{interface.api_url}#{BASE}/list?#{URI.encode_www_form(query)}",
128
129
  {
129
- Authorization: i.auth,
130
- 'User-Agent': i.user_agent
130
+ Authorization: interface.auth,
131
+ 'User-Agent': interface.user_agent
131
132
  }
132
133
  )
133
134
  end
134
135
 
135
- def list_user(i, id, query)
136
+ def list_user(interface, id, query)
136
137
  WeebSh::API.request(
137
138
  :get,
138
- "#{i.api_url}#{BASE}/list/#{id}?#{URI.encode_www_form(query)}",
139
+ "#{interface.api_url}#{BASE}/list/#{id}?#{URI.encode_www_form(query)}",
139
140
  {
140
- Authorization: i.auth,
141
- 'User-Agent': i.user_agent
141
+ Authorization: interface.auth,
142
+ 'User-Agent': interface.user_agent
142
143
  }
143
144
  )
144
145
  end
145
146
  end
146
147
  end
147
- end
148
+ end
@@ -74,7 +74,6 @@ module WeebSh
74
74
 
75
75
  # Represents an image for toph
76
76
  class WeebImage < PreviewImage
77
-
78
77
  # @return [true, false] whether or not this image is nsfw
79
78
  attr_reader :nsfw
80
79
  alias_method :nsfw?, :nsfw
@@ -138,7 +137,7 @@ module WeebSh
138
137
  end
139
138
 
140
139
  # Delete this image
141
- def delete()
140
+ def delete
142
141
  @interface.delete_image(self)
143
142
  end
144
143
  alias_method :remove, :delete
@@ -4,6 +4,7 @@ require 'weeb/interfaces/shimakaze'
4
4
  require 'weeb/interfaces/tama'
5
5
 
6
6
  module WeebSh
7
+ # Wrapper class that ties all modules together
7
8
  class Client
8
9
  # @return [String] the authorization used in weeb.sh.
9
10
  attr_reader :auth
@@ -4,6 +4,5 @@ require 'weeb/data'
4
4
  module WeebSh
5
5
  # Image Generation API
6
6
  class Korra < Interface
7
-
8
7
  end
9
- end
8
+ end
@@ -4,6 +4,5 @@ require 'weeb/data'
4
4
  module WeebSh
5
5
  # Reputation API
6
6
  class Shimakaze < Interface
7
-
8
7
  end
9
- end
8
+ end
@@ -4,6 +4,5 @@ require 'weeb/data'
4
4
  module WeebSh
5
5
  # Settings API
6
6
  class Tama < Interface
7
-
8
7
  end
9
- end
8
+ end
@@ -4,7 +4,6 @@ require 'weeb/data'
4
4
  module WeebSh
5
5
  # Image API
6
6
  class Toph < Interface
7
-
8
7
  # Uploads an image.
9
8
  # @param resource [File, String] the file to upload, this can either be a File, a URL or a path.
10
9
  # @param type [String] the type of image this is in.
@@ -15,18 +14,18 @@ module WeebSh
15
14
  # @return [Image] Returns image that was uploaded.
16
15
  def upload(resource, type, hidden: false, tags: [], nsfw: false, source: nil)
17
16
  tags = tags.map { |t| t.name if t.is_a(Tag) }
18
- if resource.is_a?(String) and URI(resource).host.nil?
17
+ if resource.is_a?(String) && URI(resource).host.nil?
19
18
  begin
20
19
  resource = File.new(File.absolute_path(resource), 'rb')
21
20
  rescue Errno::ENOENT, Errno::EACCES, Errno::ENAMETOOLONG => e
22
21
  errstring = 'Unknown'
23
22
  case e.class.name
24
- when 'Errno::ENOENT'
25
- errstring = 'File Not Found'
26
- when 'Errno::EACCES'
27
- errstring = 'Permission Denied'
28
- when 'Errno::ENAMETOOLONG'
29
- errstring = 'Name Too Long'
23
+ when 'Errno::ENOENT'
24
+ errstring = 'File Not Found'
25
+ when 'Errno::EACCES'
26
+ errstring = 'Permission Denied'
27
+ when 'Errno::ENAMETOOLONG'
28
+ errstring = 'Name Too Long'
30
29
  end
31
30
  raise WeebSh::Err::FileError, "Error initializing file '${resource}' | #{errstring} | #{e.class.name}"
32
31
  end
@@ -100,7 +99,7 @@ module WeebSh
100
99
  # @param tags [Array<String, Tag>] the affected tags
101
100
  # @return [WeebImage] Returns the image with the given ID.
102
101
  def add_tags_to_image(image, tags)
103
- id = id.resolve_id if id.respond_to?(:resolve_id)
102
+ image = image.resolve_id if id.respond_to?(:resolve_id)
104
103
  tags = tags.map { |t| t.name if t.is_a(Tag) }
105
104
  WeebImage.new(API::Toph.add_tags_to_image(self, image, tags), self)
106
105
  end
@@ -110,7 +109,7 @@ module WeebSh
110
109
  # @param tags [Array<String, Tag>] the affected tags
111
110
  # @return [WeebImage] Returns the image with the given ID.
112
111
  def remove_tags_to_image(image, tags)
113
- id = id.resolve_id if id.respond_to?(:resolve_id)
112
+ image = image.resolve_id if id.respond_to?(:resolve_id)
114
113
  tags = tags.map { |t| t.name if t.is_a(Tag) }
115
114
  WeebImage.new(API::Toph.remove_tags_to_image(self, image, tags), self)
116
115
  end
@@ -141,4 +140,4 @@ module WeebSh
141
140
 
142
141
  # Alias for the class {Toph}
143
142
  Image = Toph
144
- end
143
+ end
@@ -1,3 +1,3 @@
1
1
  module WeebSh
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weeb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Snazzah
@@ -14,30 +14,30 @@ dependencies:
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
- name: pry
28
+ name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.49.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.49.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rest-client
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.5.1
95
+ rubygems_version: 2.7.6
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: A gem that utilizes the weeb.sh API.