zype 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zype/base_model.rb +13 -2
- data/lib/zype/client.rb +13 -3
- data/lib/zype/configuration.rb +2 -1
- data/lib/zype/models/categories.rb +4 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1be9423e4d243aa33d4517c5ec224cbc1f6a2825e871543702c82063977733b
|
4
|
+
data.tar.gz: 935a274012b4f2b973a155a1970d4fa1f1155bffcf495de873fd8f81f5000540
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25156f8c688c584968045f386ab53421e1fedc2848fdff08511b69ee95d4159bb41e6f338a744196f77292b7d16e6e2e19f20c3643ac6f17c659b5ff777f9ebe
|
7
|
+
data.tar.gz: 22334225aa1b5e0e6ef7419e7b80ab33851e022a710a60c53eacc6b99cbbaa18e905b9eb509dde4cb83be65b73bc8c0c360a37e91a800b95e31bc50c518845c8
|
data/lib/zype/base_model.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Zype
|
2
2
|
class BaseModel
|
3
3
|
attr_reader :client, :path
|
4
|
+
ACCEPTED_KEYS = %i(api_key app_key)
|
5
|
+
class InvalidKey < StandardError; end
|
4
6
|
|
5
|
-
def initialize
|
6
|
-
@client = Client.new
|
7
|
+
def initialize(auth_method='api_key')
|
8
|
+
@client = Client.new(auth_method)
|
7
9
|
@path = generate_path
|
8
10
|
end
|
9
11
|
|
@@ -48,6 +50,15 @@ module Zype
|
|
48
50
|
client.execute(method: :delete, path: "/#{path}/#{id}")
|
49
51
|
end
|
50
52
|
|
53
|
+
# Sets the authentication method for calling the API
|
54
|
+
#
|
55
|
+
# @param auth_method [String] one of 'api_key' or 'app_key'
|
56
|
+
def auth=(auth_method)
|
57
|
+
raise InvalidKey unless ACCEPTED_KEYS.include?(auth_method.to_sym)
|
58
|
+
|
59
|
+
@client = Client.new(auth_method)
|
60
|
+
end
|
61
|
+
|
51
62
|
private
|
52
63
|
|
53
64
|
def generate_path
|
data/lib/zype/client.rb
CHANGED
@@ -28,8 +28,8 @@ module Zype
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def initialize
|
32
|
-
@headers = { "Content-Type" => "application/json"
|
31
|
+
def initialize(auth_method='api_key')
|
32
|
+
@headers = { "Content-Type" => "application/json" }.merge(authentication(auth_method))
|
33
33
|
self.class.base_uri Zype.configuration.host
|
34
34
|
end
|
35
35
|
|
@@ -50,7 +50,9 @@ module Zype
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def execute(method:, path:, params: {})
|
53
|
-
|
53
|
+
if Zype.configuration.api_key.to_s.empty?
|
54
|
+
raise NoApiKey if Zype.configuration.app_key.to_s.empty?
|
55
|
+
end
|
54
56
|
|
55
57
|
resp = self.send(method, path: path, params: params)
|
56
58
|
if resp.success?
|
@@ -66,5 +68,13 @@ module Zype
|
|
66
68
|
error_type = ERROR_TYPES[code] || GenericError
|
67
69
|
raise error_type.new(message)
|
68
70
|
end
|
71
|
+
|
72
|
+
def authentication(auth_method)
|
73
|
+
if auth_method.to_sym == :api_key
|
74
|
+
{ 'x-zype-key' => Zype.configuration.api_key }
|
75
|
+
else
|
76
|
+
{ 'x-zype-app-key' => Zype.configuration.app_key }
|
77
|
+
end
|
78
|
+
end
|
69
79
|
end
|
70
80
|
end
|
data/lib/zype/configuration.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zype
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zype
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/zype/base_model.rb
|
63
63
|
- lib/zype/client.rb
|
64
64
|
- lib/zype/configuration.rb
|
65
|
+
- lib/zype/models/categories.rb
|
65
66
|
- lib/zype/models/encoders.rb
|
66
67
|
- lib/zype/models/live_events.rb
|
67
68
|
- lib/zype/models/playlists.rb
|