selly 1.1.2 → 2.0.1

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
  SHA1:
3
- metadata.gz: 480c3ac08d9f568f20a1acb9b52b5c64784fc3d0
4
- data.tar.gz: 889ddbc3955359f7951fc7289fbf23fa73bb8e3a
3
+ metadata.gz: 231d308af9ae1960f66c512426dea854dcb9d975
4
+ data.tar.gz: bb97594ca94e71a2d4bb1413b6439bbf601d7c12
5
5
  SHA512:
6
- metadata.gz: 2c70d0621716e184e89b033af239be95161c7775089827909d1e00dbbce14fbca4b8155522c407f9331fdb46c2393facc4645ac0dd10ee858dc787502de9169d
7
- data.tar.gz: 62e39d559157546cb1e503b7ef7637ee95c5cf9e813ed268706413240f99cf493baa93b47faf8a3b70610873bc3e4cd293527f88f86918fc9e9dc25db29dd91c
6
+ metadata.gz: b55c6f694bb5cbe8c56adf5ccca61bf26cc333bfdbd71de621f612193ec03af056426b05c3798941c59dbeb2a018fc48c13c152c74c89f022c0693e09159f495
7
+ data.tar.gz: 145d13778d8965aea2cd7cdcb89a39408f000b46072f7ac59f814675b141d099d060b7358f4734dc47c67179a218d1536d53ea0ef45424ba0d6e90b263e5139d
data/.gitignore CHANGED
File without changes
File without changes
data/Gemfile CHANGED
File without changes
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
File without changes
data/bin/setup CHANGED
File without changes
@@ -1,8 +1,9 @@
1
1
  require 'selly/version'
2
+ require 'selly/selly_error'
2
3
  require 'selly/operations/create'
3
- require 'selly/operations/destroy'
4
4
  require 'selly/operations/list'
5
5
  require 'selly/operations/show'
6
+ require 'selly/operations/update'
6
7
  require 'selly/resource'
7
8
  require 'selly/blacklist'
8
9
  require 'selly/exchange_rates'
@@ -14,7 +15,7 @@ require 'selly/statistics'
14
15
  require 'base64'
15
16
 
16
17
  module Selly
17
- API_ROOT = 'https://selly.gg/api'.freeze
18
+ API_ROOT = 'https://selly.gg/api/v2'.freeze
18
19
  USER_AGENT = "[Selly Ruby v#{VERSION}] Ruby-#{RUBY_VERSION} - #{RUBY_PLATFORM}".freeze
19
20
  JSON_MIME = 'application/json'.freeze
20
21
 
@@ -1,5 +1,15 @@
1
1
  module Selly
2
2
  class Blacklist < Resource
3
3
  extend Selly::Operations::List
4
+ extend Selly::Operations::Create
5
+ extend Selly::Operations::Update
6
+
7
+ def create(params)
8
+ super({blacklist: params})
9
+ end
10
+
11
+ def update(id, params)
12
+ super(id, {blacklist: params})
13
+ end
4
14
  end
5
15
  end
@@ -0,0 +1,16 @@
1
+ module Selly
2
+ class Coupons < Resource
3
+ extend Selly::Operations::List
4
+ extend Selly::Operations::Show
5
+ extend Selly::Operations::Create
6
+ extend Selly::Operations::Update
7
+
8
+ def create(params)
9
+ super({coupon: params})
10
+ end
11
+
12
+ def update(id, params)
13
+ super(id, {coupon: params})
14
+ end
15
+ end
16
+ end
File without changes
@@ -1,11 +1,16 @@
1
- require 'http'
2
-
3
- module Selly
4
- module Operations
5
- module Create
6
- def create(params = {})
7
- HTTP.post("#{API_ROOT}#{resource_url}", headers: Selly.request_headers, form: params).parse
8
- end
9
- end
10
- end
1
+ require 'http'
2
+
3
+ module Selly
4
+ module Operations
5
+ module Create
6
+ def create(params = {})
7
+ response = HTTP.post("#{API_ROOT}#{resource_url}", headers: Selly.request_headers, json: params)
8
+
9
+ parsed = response.parse
10
+ if parsed.class == Hash && (response.code < 200 || response.code > 300)
11
+ raise SellyError.new(parsed['errors']), parsed['message']
12
+ end
13
+ end
14
+ end
15
+ end
11
16
  end
@@ -4,7 +4,12 @@ module Selly
4
4
  module Operations
5
5
  module List
6
6
  def list(options = {})
7
- HTTP.get("#{API_ROOT}#{resource_url}", headers: Selly.request_headers, params: options).parse
7
+ response = HTTP.get("#{API_ROOT}#{resource_url}", headers: Selly.request_headers, params: options)
8
+
9
+ parsed = response.parse
10
+ if parsed.class == Hash && (response.code < 200 || response.code > 300)
11
+ raise SellyError.new(parsed['errors']), parsed['message']
12
+ end
8
13
  end
9
14
  end
10
15
  end
@@ -4,7 +4,12 @@ module Selly
4
4
  module Operations
5
5
  module Show
6
6
  def show(resource_id, options = {})
7
- HTTP.get("#{API_ROOT}#{resource_url}/#{resource_id}", headers: Selly.request_headers, params: options).parse
7
+ response = HTTP.get("#{API_ROOT}#{resource_url}/#{resource_id}", headers: Selly.request_headers, params: options)
8
+
9
+ parsed = response.parse
10
+ if parsed.class == Hash && (response.code < 200 || response.code > 300)
11
+ raise SellyError.new(parsed['errors']), parsed['message']
12
+ end
8
13
  end
9
14
  end
10
15
  end
@@ -0,0 +1,16 @@
1
+ require 'http'
2
+
3
+ module Selly
4
+ module Operations
5
+ module Update
6
+ def update(resource_id, params = {})
7
+ response = HTTP.put("#{API_ROOT}#{resource_url}/#{resource_id}", headers: Selly.request_headers, json: params)
8
+
9
+ parsed = response.parse
10
+ if parsed.class == Hash && (response.code < 200 || response.code > 300)
11
+ raise SellyError.new(parsed['errors']), parsed['message']
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
File without changes
@@ -1,6 +1,5 @@
1
- module Selly
2
- class Pay < Resource
3
- extend Selly::Operations::Create
4
- extend Selly::Operations::Destroy
5
- end
1
+ module Selly
2
+ class Pay < Resource
3
+ extend Selly::Operations::Create
4
+ end
6
5
  end
@@ -1,6 +1,16 @@
1
- module Selly
2
- class ProductGroups < Resource
3
- extend Selly::Operations::List
4
- extend Selly::Operations::Show
5
- end
1
+ module Selly
2
+ class ProductGroups < Resource
3
+ extend Selly::Operations::List
4
+ extend Selly::Operations::Show
5
+ extend Selly::Operations::Create
6
+ extend Selly::Operations::Update
7
+
8
+ def create(params)
9
+ super({product_group: params})
10
+ end
11
+
12
+ def update(id, params)
13
+ super(id, {product_group: params})
14
+ end
15
+ end
6
16
  end
@@ -2,5 +2,15 @@ module Selly
2
2
  class Products < Resource
3
3
  extend Selly::Operations::List
4
4
  extend Selly::Operations::Show
5
+ extend Selly::Operations::Create
6
+ extend Selly::Operations::Update
7
+
8
+ def create(params)
9
+ super({product: params})
10
+ end
11
+
12
+ def update(id, params)
13
+ super(id, {product: params})
14
+ end
5
15
  end
6
16
  end
@@ -14,7 +14,7 @@ module Selly
14
14
  string.gsub(/::/, '/').
15
15
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
16
16
  gsub(/([a-z\d])([A-Z])/, '\1_\2').
17
- tr("-", "_").
17
+ tr('-', '_').
18
18
  downcase
19
19
  end
20
20
  end
@@ -0,0 +1,7 @@
1
+ class SellyError < StandardError
2
+ attr_reader :errors
3
+
4
+ def initialize(errors = [])
5
+ @errors = errors
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Selly
2
- VERSION = '1.1.2'
2
+ VERSION = '2.0.1'
3
3
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Selly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-26 00:00:00.000000000 Z
11
+ date: 2018-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -69,17 +69,18 @@ files:
69
69
  - bin/setup
70
70
  - lib/selly.rb
71
71
  - lib/selly/blacklist.rb
72
+ - lib/selly/coupons.rb
72
73
  - lib/selly/exchange_rates.rb
73
74
  - lib/selly/operations/create.rb
74
- - lib/selly/operations/destroy.rb
75
75
  - lib/selly/operations/list.rb
76
76
  - lib/selly/operations/show.rb
77
+ - lib/selly/operations/update.rb
77
78
  - lib/selly/orders.rb
78
79
  - lib/selly/pay.rb
79
80
  - lib/selly/product_groups.rb
80
81
  - lib/selly/products.rb
81
82
  - lib/selly/resource.rb
82
- - lib/selly/statistics.rb
83
+ - lib/selly/selly_error.rb
83
84
  - lib/selly/version.rb
84
85
  - selly.gemspec
85
86
  homepage: https://selly.gg
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  version: '0'
104
105
  requirements: []
105
106
  rubyforge_project:
106
- rubygems_version: 2.6.13
107
+ rubygems_version: 2.6.14
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Ruby library for Selly's API
@@ -1,11 +0,0 @@
1
- require 'http'
2
-
3
- module Selly
4
- module Operations
5
- module Destroy
6
- def destroy(resource_id, options = {})
7
- HTTP.delete("#{API_ROOT}#{resource_url}/#{resource_id}", headers: Selly.request_headers, params: options).parse
8
- end
9
- end
10
- end
11
- end
@@ -1,17 +0,0 @@
1
- module Selly
2
- class Statistics < Resource
3
- extend Selly::Operations::Show
4
-
5
- def self.income(options = {})
6
- self.show('/income', options)
7
- end
8
-
9
- def self.day_income(options = {})
10
- self.show('/day_income', options)
11
- end
12
-
13
- def self.views(options = {})
14
- self.show('/views', options)
15
- end
16
- end
17
- end