memerator 0.1.0 → 0.1.1
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 +5 -5
- data/README.md +2 -2
- data/lib/memerator.rb +18 -7
- data/lib/memerator/errors.rb +1 -1
- data/lib/memerator/meme.rb +9 -4
- data/lib/memerator/notification.rb +2 -2
- data/lib/memerator/profile.rb +18 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e78af8225a3cbed615ca990b94c2c083572f397ca43bcf20f498cb202dfb3550
|
4
|
+
data.tar.gz: fb1815b0afb69a931d685eb28b80be04b7cdaaf6f94697ef65b095144f5df00e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9292c5fe442e65a37b0ed58c2cb7bd7653227233ebc5f23eb9c5b0724c6d9ceda1aba911a31f9043665cd72a386047dd7a81d46c7efe38c225727bf16db87a
|
7
|
+
data.tar.gz: 51309d1b877b187a9f66bc52dbae43c1306dd5b7b6173e729af19f7399d9829a0fc60a9f3d0f0e06eb4cf23fc958477cf42be608dfa5b18cad819ac3460ab54b
|
data/README.md
CHANGED
@@ -12,10 +12,10 @@ The gem is currently in Beta! Until you see that nice 1.0.0, expect bugs!
|
|
12
12
|
|
13
13
|
What the API has that this gem can't do yet:
|
14
14
|
|
15
|
-
|
15
|
+
~~* Set your username~~ Implemented in next release :)
|
16
16
|
* Get recent memes
|
17
17
|
* Get top memes
|
18
|
-
|
18
|
+
~~* Get top memers~~ Implemented in next release :)
|
19
19
|
* Submit a meme
|
20
20
|
|
21
21
|
## Usage
|
data/lib/memerator.rb
CHANGED
@@ -16,7 +16,7 @@ class Memerator
|
|
16
16
|
def user(perso)
|
17
17
|
return profile if perso.downcase == 'me'
|
18
18
|
|
19
|
-
data = JSON.parse(RestClient.get("https://memerator.me/
|
19
|
+
data = JSON.parse(RestClient.get("https://api.memerator.me/v1/profile/#{perso}", Authorization: @token))
|
20
20
|
|
21
21
|
User.new(data)
|
22
22
|
rescue RestClient::NotFound
|
@@ -25,7 +25,7 @@ class Memerator
|
|
25
25
|
|
26
26
|
# @return [Profile] your profile
|
27
27
|
def profile
|
28
|
-
data = JSON.parse(RestClient.get('https://memerator.me/
|
28
|
+
data = JSON.parse(RestClient.get('https://api.memerator.me/v1/profile/me', Authorization: @token))
|
29
29
|
Profile.new(data, token: @token)
|
30
30
|
end
|
31
31
|
|
@@ -34,7 +34,7 @@ class Memerator
|
|
34
34
|
# @raise [Memerator::Errors::InvalidMeme] if the meme does not exist.
|
35
35
|
# @return [Meme] the meme
|
36
36
|
def meme(id)
|
37
|
-
data = JSON.parse(RestClient.get("https://memerator.me/
|
37
|
+
data = JSON.parse(RestClient.get("https://api.memerator.me/v1/meme/#{id}", Authorization: @token))
|
38
38
|
|
39
39
|
Meme.new(data, token: @token)
|
40
40
|
rescue RestClient::NotFound
|
@@ -44,28 +44,39 @@ class Memerator
|
|
44
44
|
# Get a random meme
|
45
45
|
# @return [Meme] the meme
|
46
46
|
def randommeme
|
47
|
-
data = JSON.parse(RestClient.get("https://memerator.me/
|
47
|
+
data = JSON.parse(RestClient.get("https://api.memerator.me/v1/meme/random", Authorization: @token))
|
48
48
|
Meme.new(data, token: @token)
|
49
49
|
end
|
50
50
|
|
51
51
|
# @return [Stats] the site's stats
|
52
52
|
def stats
|
53
|
-
data = JSON.parse(RestClient.get('https://memerator.me/
|
53
|
+
data = JSON.parse(RestClient.get('https://api.memerator.me/v1/stats', Authorization: @token))
|
54
54
|
Stats.new(data)
|
55
55
|
end
|
56
56
|
|
57
57
|
# @return [Array<Notification>] your notifications
|
58
58
|
def notifications
|
59
|
-
notifications = JSON.parse(RestClient.get('https://memerator.me/
|
59
|
+
notifications = JSON.parse(RestClient.get('https://api.memerator.me/v1/notifications', Authorization: @token))
|
60
60
|
notifications.map { |notification_data| Notification.new(notification_data) }
|
61
61
|
end
|
62
62
|
|
63
63
|
# @return [Array<Report>] your reports
|
64
64
|
def reports
|
65
|
-
reports = JSON.parse(RestClient.get('https://memerator.me/
|
65
|
+
reports = JSON.parse(RestClient.get('https://api.memerator.me/v1/reports', Authorization: @token))
|
66
66
|
reports.map { |report_data| Report.new(report_data) }
|
67
67
|
end
|
68
68
|
|
69
|
+
# Get the top memers (by meme count)
|
70
|
+
# @return [Hash<User, Integer>] the top memers in a hash of user to their memes
|
71
|
+
def topmemers
|
72
|
+
users = JSON.parse(RestClient.get('https://api.memerator.me/v1/topmemers', Authorization: @token))
|
73
|
+
top = {}
|
74
|
+
users.each do |woah|
|
75
|
+
top[User.new(woah['profile'])] = woah['memes']
|
76
|
+
end
|
77
|
+
top
|
78
|
+
end
|
79
|
+
|
69
80
|
# Get the token from instantiation
|
70
81
|
attr_reader :token
|
71
82
|
end
|
data/lib/memerator/errors.rb
CHANGED
data/lib/memerator/meme.rb
CHANGED
@@ -23,6 +23,11 @@ class Memerator::Meme
|
|
23
23
|
@data['url']
|
24
24
|
end
|
25
25
|
|
26
|
+
# @return [Float] the total amount of ratings.
|
27
|
+
def total_ratings
|
28
|
+
@data['rating']['total']
|
29
|
+
end
|
30
|
+
|
26
31
|
# @return [Float] the average rating.
|
27
32
|
def average_rating
|
28
33
|
@data['rating']['average']
|
@@ -60,7 +65,7 @@ class Memerator::Meme
|
|
60
65
|
# @raise [Memerator::Errors::InvalidToken] if your token is bad.
|
61
66
|
# @return [true] when successful
|
62
67
|
def disable!
|
63
|
-
response = JSON.parse(RestClient.put("https://memerator.me/
|
68
|
+
response = JSON.parse(RestClient.put("https://api.memerator.me/v1/meme/#{memeid}/disable", {}, Authorization: @token))
|
64
69
|
@data['disabled'] = true
|
65
70
|
response['success']
|
66
71
|
rescue RestClient::NotFound
|
@@ -77,7 +82,7 @@ class Memerator::Meme
|
|
77
82
|
# @raise [Memerator::Errors::InvalidToken] if your token is bad.
|
78
83
|
# @return [true] when successful
|
79
84
|
def enable!
|
80
|
-
response = JSON.parse(RestClient.put("https://memerator.me/
|
85
|
+
response = JSON.parse(RestClient.put("https://api.memerator.me/v1/meme/#{memeid}/enable", {}, Authorization: @token))
|
81
86
|
@data['disabled'] = false
|
82
87
|
response['success']
|
83
88
|
rescue RestClient::NotFound
|
@@ -96,7 +101,7 @@ class Memerator::Meme
|
|
96
101
|
def caption=(newcap)
|
97
102
|
raise Memerator::Errors::DisabledMeme, "This meme is disabled and can't be interacted with" if disabled?
|
98
103
|
|
99
|
-
response = JSON.parse(RestClient.put("https://memerator.me/
|
104
|
+
response = JSON.parse(RestClient.put("https://api.memerator.me/v1/meme/#{memeid}/caption", {"caption" => newcap}.to_json, Authorization: @token, 'Content-Type': :json))
|
100
105
|
@data['caption'] = newcap
|
101
106
|
response['success']
|
102
107
|
rescue RestClient::NotFound
|
@@ -130,7 +135,7 @@ class Memerator::Meme
|
|
130
135
|
raise Memerator::Errors::DisabledMeme, "This meme is disabled and can't be interacted with" if disabled?
|
131
136
|
raise ArgumentError, "Your rating is bad mate!" if rating > 5 || rating < 1 || rating.to_i != rating
|
132
137
|
|
133
|
-
response = JSON.parse(RestClient.post("https://memerator.me/
|
138
|
+
response = JSON.parse(RestClient.post("https://api.memerator.me/v1/meme/#{memeid}/rate", {"rating" => rating}.to_json, Authorization: @token, 'Content-Type': :json))
|
134
139
|
response['success']
|
135
140
|
rescue RestClient::NotFound
|
136
141
|
raise Memerator::Errors::NoPermission, "your token doesn't grant you access to this meme"
|
@@ -30,7 +30,7 @@ class Memerator::Notification
|
|
30
30
|
@data['raw']
|
31
31
|
end
|
32
32
|
|
33
|
-
# The type is mostly used internally but is useful for
|
33
|
+
# The type is mostly used internally but is useful for clients implementing notification sorting.
|
34
34
|
# Type 0 is a meme rating notification
|
35
35
|
# Type 1 is a follow notification
|
36
36
|
# Type 2 is a notice.
|
@@ -50,7 +50,7 @@ class Memerator::Notification
|
|
50
50
|
|
51
51
|
# For meme ratings, the meme rating is returned, if you need it!
|
52
52
|
# @return [Integer, nil] the meme rating, if type == 0
|
53
|
-
def
|
53
|
+
def rating
|
54
54
|
return nil if @data['meme'].nil?
|
55
55
|
|
56
56
|
@data['meme']['rating']
|
data/lib/memerator/profile.rb
CHANGED
@@ -17,10 +17,27 @@ class Memerator::Profile < Memerator::User
|
|
17
17
|
Time.parse(@data['pro']['since'])
|
18
18
|
end
|
19
19
|
|
20
|
+
# Set your username
|
21
|
+
# Username Requirements:
|
22
|
+
# Be between 2 and 32 characters.
|
23
|
+
# Not be in use
|
24
|
+
# Can't be only numbers
|
25
|
+
# Can't have special characters Allowed: (A-Z|a-z|0-9|_|.)
|
26
|
+
# @return [true] if the username was changed
|
27
|
+
# @raise [ArgumentError] if the requirements are not met
|
28
|
+
def username=(new_username)
|
29
|
+
response = JSON.parse(RestClient.post("https://api.memerator.me/v1/profile/me", { "username" => new_username }.to_json, Authorization: @token, 'Content-Type': :json))
|
30
|
+
@data['username'] = new_username
|
31
|
+
response['success']
|
32
|
+
rescue RestClient::BadRequest => error
|
33
|
+
why = JSON.parse(error.response.body)['error']
|
34
|
+
raise ArgumentError, "Your username does not match the requirements! #{why}"
|
35
|
+
end
|
36
|
+
|
20
37
|
# Update your Bio!
|
21
38
|
# @return [true] the success
|
22
39
|
def bio=(new_bio)
|
23
|
-
response = JSON.parse(RestClient.post("https://memerator.me/
|
40
|
+
response = JSON.parse(RestClient.post("https://api.memerator.me/v1/profile/me", { "bio" => new_bio }.to_json, Authorization: @token, 'Content-Type': :json))
|
24
41
|
@data['bio'] = new_bio
|
25
42
|
response['success']
|
26
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.1.0.rc1
|
41
|
-
description: The Memerator.me API
|
41
|
+
description: The Memerator.me API Library wrapper in Ruby.
|
42
42
|
email: chew@memerator.me
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
@@ -78,9 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.6.14
|
81
|
+
rubygems_version: 3.0.6
|
83
82
|
signing_key:
|
84
83
|
specification_version: 4
|
85
|
-
summary: The Memerator.me API
|
84
|
+
summary: The Memerator.me API Library wrapper in Ruby
|
86
85
|
test_files: []
|