wallhaven 0.3.1 → 1.0.0

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
2
  SHA256:
3
- metadata.gz: 7ffa413abbbc9af19d7aac34870efb2918e45ae13ea9e8a8551c352772231dd1
4
- data.tar.gz: 4ea166486ff127f7938a99e2202c6e542b9af913c2192e57d88675d45281d6a8
3
+ metadata.gz: eb9976e5499802aebecf6cd8d7dcc4ac1d753e887f532f1a45a0f88ddd5e5323
4
+ data.tar.gz: 0caee8f54dd0bda864ba5e6059d3cffb8f58623fc074def59e6504248178ad8d
5
5
  SHA512:
6
- metadata.gz: 74b605958fff202b7c1107af9a3ca5f18d48e290630691ac167e560570b55628596c0d5165e29d4d7c31f8b1c6ab106acb785ea1301a233ba71e9b7adff4e90c
7
- data.tar.gz: be7dee81e5ad9c122e8ea4a60f958487fb54254e5c7e71b1c10ca6deed4ae03aa5bd8663fbe936de01bfc76045fce56fb87b52bc7597ba66a3d2d27a6f56f348
6
+ metadata.gz: 2d7bf4988081beaf43df3cfda2b2a946dbf54d5b2dc2a5972747dd351d75360950f698f978c427c64c557493115082bff9818cd730cd81a5e23da780726d1d1a
7
+ data.tar.gz: 16068a90ee840df863f7d13eb03416ccfc5ba9cdc91868e9d0c00067dfe4fe3ed02646afc0dd74412b34499fe369060dee78e01d753bfb1b7370abdbf01ee155
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wallhaven (0.2.1)
4
+ wallhaven (0.3.1)
5
5
  httparty (~> 0.17)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  A simple gem to interact with Wallhaven's API.
6
6
 
7
+ You can find the official API documentation [here](https://wallhaven.cc/help/api).
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -26,14 +28,17 @@ Or install it yourself as:
26
28
  ## Usage
27
29
 
28
30
  1. Setup your API key
29
- `Wallhaven::Client.new(api_key: <your_key>)`
30
31
 
31
- 2. Make a request
32
+ `Wallhaven.apikey = "<your_key>"`
33
+
34
+ **Note**: You can still make requests without an apikey, but you won't be able to get NSFW results.
35
+
36
+ 2. Make a request to an endpoint:
32
37
  ```ruby
33
- Wallhaven::Wallpaper.get(<some_id>)
34
- Wallhaven::Tag.get(<some_id>)
35
- Wallhaven::Search.get
36
- Wallhaven::Settings.get
38
+ Wallhaven.wallpaper(<some_id>)
39
+ Wallhaven.tag(<some_id>)
40
+ Wallhaven.search({ filter_1: some_filter, filter_2: some_other_filter })
41
+ Wallhaven.settings
37
42
  ```
38
43
 
39
44
  ## Gem Development
@@ -1,9 +1,5 @@
1
1
  require 'wallhaven/version'
2
+ require 'wallhaven/wallhaven'
2
3
 
3
4
  module Wallhaven
4
- autoload :Client, 'wallhaven/client'
5
- autoload :Search, 'wallhaven/search'
6
- autoload :Settings, 'wallhaven/settings'
7
- autoload :Tag, 'wallhaven/tag'
8
- autoload :Wallpaper, 'wallhaven/wallpaper'
9
5
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Hash
4
+ def deep_merge(other_hash, &block)
5
+ dup.deep_merge!(other_hash, &block)
6
+ end
7
+
8
+ # Same as +deep_merge+, but modifies +self+.
9
+ def deep_merge!(other_hash, &block)
10
+ merge!(other_hash) do |key, this_val, other_val|
11
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
12
+ this_val.deep_merge(other_val, &block)
13
+ elsif block_given?
14
+ block.call(key, this_val, other_val)
15
+ else
16
+ other_val
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Wallhaven
2
- VERSION = "0.3.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'httparty'
2
+
3
+ module Wallhaven
4
+ include HTTParty
5
+ base_uri 'https://wallhaven.cc/api/v1/'
6
+
7
+ class << self
8
+ attr_accessor :apikey
9
+ end
10
+
11
+ def self.wallpaper(id)
12
+ parse get("/w/#{id}", query)
13
+ end
14
+
15
+ def self.search(params = {})
16
+ parse get('/search', query(params ))
17
+ end
18
+
19
+ def self.tag(id)
20
+ parse get("/tag/#{id}", query)
21
+ end
22
+
23
+ def self.settings
24
+ parse get("/settings", query)
25
+ end
26
+
27
+ private
28
+
29
+ def self.parse(response)
30
+ response.parsed_response["data"]
31
+ end
32
+
33
+ def self.query(params = {})
34
+ { query: { apikey: apikey }.merge(params) }
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wallhaven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rojo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-07 00:00:00.000000000 Z
11
+ date: 2019-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,12 +98,9 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - lib/wallhaven.rb
101
- - lib/wallhaven/client.rb
102
- - lib/wallhaven/search.rb
103
- - lib/wallhaven/settings.rb
104
- - lib/wallhaven/tag.rb
101
+ - lib/wallhaven/core_ext/hash/deep_merge.rb
105
102
  - lib/wallhaven/version.rb
106
- - lib/wallhaven/wallpaper.rb
103
+ - lib/wallhaven/wallhaven.rb
107
104
  - wallhaven.gemspec
108
105
  homepage: https://github.com/soyrojo/wallhaven
109
106
  licenses:
@@ -1,14 +0,0 @@
1
- require 'httparty'
2
-
3
- module Wallhaven
4
- class Client
5
- include HTTParty
6
- base_uri 'https://wallhaven.cc/api/v1/'
7
-
8
- attr_accessor :api_key
9
-
10
- def initialize(api_key: nil)
11
- @@api_key = api_key
12
- end
13
- end
14
- end
@@ -1,8 +0,0 @@
1
- module Wallhaven
2
- class Search < Client
3
-
4
- def self.get
5
- Client.get('/search/', { query: { apikey: @@api_key }})
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Wallhaven
2
- class Settings < Client
3
-
4
- def self.get(id)
5
- Client.get('/settings/', { query: { apikey: @@api_key }})
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Wallhaven
2
- class Tag < Client
3
-
4
- def self.get(id)
5
- Client.get('/tag/' + id.to_s, { query: { apikey: @@api_key }})
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Wallhaven
2
- class Wallpaper < Client
3
-
4
- def self.get(id)
5
- Client.get('/w/' + id.to_s, { query: { apikey: @@api_key }})
6
- end
7
- end
8
- end