shoptet 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shoptet.rb +36 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d9c548dd730e3b59fb8ae843dab0fdae19b4779c27042c0aa5f01bed576cc88
4
- data.tar.gz: 610aee2527b42a799c771b172a1fa54b942b5d0823080f2f2761271ce8efd6dc
3
+ metadata.gz: 8facc56cfe2afc649cbad1f5094830d94d83f1f8d3d564e8886f17efe1b5bc87
4
+ data.tar.gz: 82c8517d218cc6182c54620e1161428d992a43e70364c23438fb0970bf303a6f
5
5
  SHA512:
6
- metadata.gz: 334fc975ad12a81db120372b3478369db2ed4c67df97e7bbc6cd62f2fe875e1f39f2366ee8f82330edd80e517eb592cf3962491d5328aeaf9cb67a72b3d41352
7
- data.tar.gz: c627078af8708d7ad6beec828d1e19ff22e6e088042e1fd09d67c4ae86307e4e76093499e7041ac096d0326400157681121ffb5c8e5618f9de9299e824701ff1
6
+ metadata.gz: 3ff366765e02c7fe423368d0afa62bda693811c96f4f681b490161274228d39e0713cca821d4d49768c17e5f7de51e80a291bad2473e5087ff3bf4f22ccf872b
7
+ data.tar.gz: c74cda5f867dd363950b031cd4995fdf9585b843e8f66b11bdd7ec4f5e8e3f728e8340d7cebf796756133b05b3b3678716994692a46b169454e680b8a357f516
@@ -11,7 +11,7 @@ class Shoptet
11
11
  end
12
12
 
13
13
  def self.version
14
- '0.0.6'
14
+ '0.0.7'
15
15
  end
16
16
 
17
17
  def self.ar_on_token_error(model)
@@ -31,9 +31,9 @@ class Shoptet
31
31
  end
32
32
  end
33
33
 
34
- def self.install uri, redirect_uri, client_id, client_secret, code
34
+ def self.install url, redirect_url, client_id, client_secret, code
35
35
  data = {
36
- 'redirect_uri' => redirect_uri,
36
+ 'redirect_uri' => redirect_url,
37
37
  'client_id' => client_id,
38
38
  'client_secret' => client_secret,
39
39
  'code' => code,
@@ -41,19 +41,49 @@ class Shoptet
41
41
  'scope' => 'api'
42
42
  }
43
43
 
44
- Shoptet::Request.post uri, data
44
+ Shoptet::Request.post url, data
45
+ end
46
+
47
+ def self.login_token url, code, client_id, client_secret, redirect_url
48
+ data = {
49
+ code: code,
50
+ grant_type: 'authorization_code',
51
+ client_id: client_id,
52
+ client_secret: client_secret,
53
+ redirect_uri: redirect_url,
54
+ scope: 'basic_eshop'
55
+ }
56
+
57
+ Shoptet::Request.post url, data
58
+ end
59
+
60
+ def self.basic_eshop url, access_token
61
+ Shoptet::Request.get url, { 'Authorization' => "Bearer #{access_token}" }
45
62
  end
46
63
 
47
64
  attr_accessor :api_token
48
65
 
49
- def initialize(oauth_url, oauth_token, api_token = nil, on_token_error = nil)
66
+ def initialize oauth_url:, oauth_token:, shop_url:, client_id:, api_token: nil, on_token_error: nil
50
67
  @oauth_url = oauth_url
51
68
  @oauth_token = oauth_token
69
+ @shop_url = shop_url
70
+ @client_id = client_id
52
71
  @api_token = api_token
53
72
  @on_token_error = on_token_error || DEFAULT_ON_TOKEN_ERROR
54
73
  end
55
74
 
56
- #TODO: return ['data'] already
75
+ def authorize_url redirect_url, state
76
+ query = {
77
+ client_id: @client_id,
78
+ state: state,
79
+ scope: 'basic_eshop',
80
+ response_type: 'code',
81
+ redirect_uri: redirect_url
82
+ }.to_query
83
+
84
+ URI("#{@shop_url}action/OAuthServer/authorize?#{query}").to_s
85
+ end
86
+
57
87
  def shop_info api_params = {}
58
88
  result = request 'https://api.myshoptet.com/api/eshop'
59
89
  result['data']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoptet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Premysl Donat