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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9a2ea73f4d8fbd2a269eac9d311b23d7d0d0a2a0c008e8f95931241c030cc4e
4
- data.tar.gz: 7fa7fc82ca88b6aaf5a0396b68b613fec84dd764892b21e8aca866f67b8f1274
3
+ metadata.gz: a1be9423e4d243aa33d4517c5ec224cbc1f6a2825e871543702c82063977733b
4
+ data.tar.gz: 935a274012b4f2b973a155a1970d4fa1f1155bffcf495de873fd8f81f5000540
5
5
  SHA512:
6
- metadata.gz: 561add775aca12eb095edd30a8d5b23b5d58b8603df5f2980922744cb87dad216325369ff72555cfc875ce84c985cdd04d04c7d76e4998ce48cca50739becf80
7
- data.tar.gz: d1ca32fd59b69988dcbc3b3e7916c54986718959390bd63405400076df1a7aa4529fb2b839294b78e001d8bad8ea8493d19a1e981ed2d9121e11a80bc1228315
6
+ metadata.gz: 25156f8c688c584968045f386ab53421e1fedc2848fdff08511b69ee95d4159bb41e6f338a744196f77292b7d16e6e2e19f20c3643ac6f17c659b5ff777f9ebe
7
+ data.tar.gz: 22334225aa1b5e0e6ef7419e7b80ab33851e022a710a60c53eacc6b99cbbaa18e905b9eb509dde4cb83be65b73bc8c0c360a37e91a800b95e31bc50c518845c8
@@ -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", "x-zype-key" => Zype.configuration.api_key }
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
- raise NoApiKey if Zype.configuration.api_key.to_s.empty?
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
@@ -1,9 +1,10 @@
1
1
  module Zype
2
2
  class Configuration
3
- attr_accessor :api_key, :host
3
+ attr_accessor :api_key, :host, :app_key
4
4
 
5
5
  def initialize
6
6
  @api_key = nil
7
+ @app_key = nil
7
8
  @host = 'api.zype.com'
8
9
  end
9
10
  end
@@ -0,0 +1,4 @@
1
+ module Zype
2
+ class Categories < Zype::BaseModel
3
+ end
4
+ end
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.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