bitrix24_cloud_api 0.1.0 → 0.1.3

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.
Files changed (35) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/README.md +18 -41
  4. data/bitrix24_cloud_api.gemspec +7 -10
  5. data/lib/bitrix24_cloud_api/CRM/activity.rb +5 -0
  6. data/lib/bitrix24_cloud_api/CRM/additional_entities.rb +58 -18
  7. data/lib/bitrix24_cloud_api/CRM/address.rb +9 -0
  8. data/lib/bitrix24_cloud_api/CRM/deal_category.rb +22 -0
  9. data/lib/bitrix24_cloud_api/CRM/externalchannel.rb +30 -0
  10. data/lib/bitrix24_cloud_api/CRM/invoice.rb +10 -0
  11. data/lib/bitrix24_cloud_api/CRM/live_feed_message.rb +11 -0
  12. data/lib/bitrix24_cloud_api/CRM/measure.rb +6 -0
  13. data/lib/bitrix24_cloud_api/CRM/product.rb +20 -0
  14. data/lib/bitrix24_cloud_api/CRM/product_row.rb +11 -0
  15. data/lib/bitrix24_cloud_api/CRM/property.rb +11 -0
  16. data/lib/bitrix24_cloud_api/CRM/requisite.rb +54 -0
  17. data/lib/bitrix24_cloud_api/CRM/status.rb +16 -0
  18. data/lib/bitrix24_cloud_api/CRM/userfield.rb +22 -0
  19. data/lib/bitrix24_cloud_api/CRM/vat.rb +6 -0
  20. data/lib/bitrix24_cloud_api/aliases.rb +7 -0
  21. data/lib/bitrix24_cloud_api/base.rb +10 -4
  22. data/lib/bitrix24_cloud_api/client.rb +27 -26
  23. data/lib/bitrix24_cloud_api/common_methods/common_methods.rb +62 -0
  24. data/lib/bitrix24_cloud_api/crm.rb +11 -1
  25. data/lib/bitrix24_cloud_api/hash_conversions.rb +37 -0
  26. data/lib/bitrix24_cloud_api/version.rb +1 -1
  27. data/lib/bitrix24_cloud_api.rb +3 -1
  28. metadata +72 -24
  29. data/.idea/.name +0 -1
  30. data/.idea/.rakeTasks +0 -7
  31. data/.idea/bitrix24_cloud_api.iml +0 -19
  32. data/.idea/misc.xml +0 -29
  33. data/.idea/modules.xml +0 -8
  34. data/.idea/vcs.xml +0 -6
  35. data/.idea/workspace.xml +0 -998
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 84085ace187be8919be8a75f9504323d4de260c0
4
- data.tar.gz: d122f691d8b5703228acdf08c12575b89d52f6e0
2
+ SHA256:
3
+ metadata.gz: b92169a6152fa854ee3bda27b04c58fd53af4d8106797b4d307ecfc8c8a6ce3e
4
+ data.tar.gz: 48246a7ad48ae1228cd533a45ae1c85a238170e042ad72ddb0ae6e02fdf3d033
5
5
  SHA512:
6
- metadata.gz: 0e04975c75b6df639cd8ac3bb685d00e19b6ee8335f181c2cdb1e92a72492c2b63c7095cb4800e9375d8fc57c69d8442c6d38af213acbe6db7b55d330dcaffad
7
- data.tar.gz: e1a79ab3a3b32bf317727afffe3e58757b0819fd008c7ae4e734992fd8ca734b584ed560b5d1c4daa259a7a49439662c27e38423083233253fd5a96d9d3e7e39
6
+ metadata.gz: 906d484f88507ff7ac490753c3230b11e0b9fe80855ec5a314c0c73d3683818db8ec0945a85b0a2e83a3e476f3ca7d39a92a3e0ae926eaebb9042b3acdbd9454
7
+ data.tar.gz: 8f1c16284be468be1be707c215aa3281e47bcf0c3a131651e23b84173a61d2719f31ad90785f94b36d48f1f9439056d8850a93e4df3ebd3933d7387b17a4e65b
data/.gitignore CHANGED
@@ -7,4 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /.idea/
10
+ .idea/
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
+ [![Build Status](https://travis-ci.org/nononoy/bitrix24_cloud_api.svg?branch=master)](https://travis-ci.org/nononoy/bitrix24_cloud_api)
2
+
1
3
  # Bitrix24CloudApi
2
4
 
3
- Ruby library for [Bitrix24 REST API](https://dev.1c-bitrix.ru/rest_help/index.php) **(only Cloud version)**.
5
+ Ruby library for [Bitrix24 REST API](https://dev.1c-bitrix.ru/rest_help/index.php).
4
6
 
5
7
  ## Installation
6
8
 
@@ -48,49 +50,24 @@ To **refresh** oauth2 **access_token** use:
48
50
 
49
51
  it's response contains a hash with refreshed *oauth2 credentials*.
50
52
 
51
- If you already **have a valid access_token** add it to the client's attributes `@client.update(access_token: access_token)` or create a new client instance `@client = Bitrix24CloudApi::Client.new(access_token: access_token)`.
53
+ If you already **have a valid access_token** add it to the client's attributes `@client.update(access_token: access_token)` or create a new client instance
54
+ ```
55
+ @client = Bitrix24CloudApi::Client.new(access_token: access_token, endpoint: api_endpoint).
56
+ ```
52
57
 
53
- ### CRM
58
+ ### Aliases
59
+
60
+ ```
61
+ B24 == Bitrix24CloudApi
62
+ B24_CRM == Bitrix24CloudApi::CRM
63
+ ```
64
+
65
+ So, `Bitrix24CloudApi::CRM::Lead.add(@client, params)` equals to `B24_CRM::Lead.add(@client, params)`.
66
+
54
67
 
55
- Available models
68
+ ### CRM
56
69
 
57
- * Bitrix24CloudApi::CRM::Activity
58
- * Bitrix24CloudApi::CRM::ACTIVITY::Communication
59
-
60
- * Bitrix24CloudApi::CRM::Company
61
- * Bitrix24CloudApi::CRM::COMPANY::Userfield
62
-
63
- * Bitrix24CloudApi::CRM::Contact
64
- * Bitrix24CloudApi::CRM::CONTACT::Userfield
65
-
66
- * Bitrix24CloudApi::CRM::Currency
67
- * Bitrix24CloudApi::CRM::CURRENCY::Localizations
68
-
69
- * Bitrix24CloudApi::CRM::Deal
70
- * Bitrix24CloudApi::CRM::DEAL::Userfield
71
- * Bitrix24CloudApi::CRM::DEAL::ProductRows
72
-
73
- * Bitrix24CloudApi::CRM::Lead
74
- * Bitrix24CloudApi::CRM::LEAD::Userfield
75
- * Bitrix24CloudApi::CRM::LEAD::ProductRows
76
-
77
- * Bitrix24CloudApi::CRM::Quote
78
- * Bitrix24CloudApi::CRM::QUOTE::Userfield
79
- * Bitrix24CloudApi::CRM::QUOTE::ProductRows
80
-
81
- * Bitrix24CloudApi::CRM::Localizations
82
- * Bitrix24CloudApi::CRM::Product
83
- * Bitrix24CloudApi::CRM::ProductRows
84
- * Bitrix24CloudApi::CRM::ProductSection
85
- * Bitrix24CloudApi::CRM::Userfield
86
- * Bitrix24CloudApi::CRM::Duplicate
87
- * Bitrix24CloudApi::CRM::Enum
88
- * Bitrix24CloudApi::CRM::Invoice
89
- * Bitrix24CloudApi::CRM::InvoiceStatus
90
- * Bitrix24CloudApi::CRM::Communication
91
- * Bitrix24CloudApi::CRM::Catalog
92
-
93
- All models' metods are provided. Second attribute in method call is a hash for bitrix24 REST API query. Example:
70
+ All REST API methods are provided. Second attribute in method call is a hash for bitrix24 REST API query. Example:
94
71
 
95
72
  params = { fields: {TITLE: title, PHONE: [VALUE: phone, VALUE_TYPE: "WORK"]} }
96
73
  Bitrix24CloudApi::CRM::Lead.add(@client, params)
@@ -14,22 +14,19 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/nononoy/bitrix24_cloud_api"
15
15
  spec.license = "MIT"
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- # if spec.respond_to?(:metadata)
20
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- # else
22
- # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
- # end
24
-
25
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
18
  spec.bindir = "exe"
27
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
20
  spec.require_paths = ["lib"]
21
+ spec.metadata["source_code_uri"] = "https://github.com/nononoy/bitrix24_cloud_api"
22
+
23
+ spec.add_runtime_dependency "oauth2", "~> 1.1"
24
+ spec.add_runtime_dependency "httparty", "~> 0.13.7"
29
25
 
30
26
  spec.add_development_dependency "bundler", "~> 1.12"
31
27
  spec.add_development_dependency "rake", "~> 10.0"
32
28
  spec.add_development_dependency "rspec", "~> 3.0"
33
- spec.add_development_dependency "oauth2", "~> 1.1"
34
- spec.add_development_dependency "httparty", "~> 0.13.7"
29
+ spec.add_development_dependency "webmock"
30
+ spec.add_development_dependency 'pry'
31
+ spec.add_development_dependency 'shoulda-matchers', "~> 2.0"
35
32
  end
@@ -11,6 +11,11 @@ module Bitrix24CloudApi
11
11
  end
12
12
 
13
13
  class Activity < Bitrix24CloudApi::Crm
14
+ [:company, :contact].each do |action|
15
+ define_singleton_method(action) do |client, query = {}|
16
+ client.make_post_request(resource_url(client, action), query)
17
+ end
18
+ end
14
19
  end
15
20
  end
16
21
  end
@@ -10,49 +10,89 @@ module Bitrix24CloudApi
10
10
  end
11
11
  end
12
12
 
13
- class Userfield < Bitrix24CloudApi::Crm
13
+ class Localizations < Bitrix24CloudApi::Crm
14
14
  class << self
15
- undef_method :fields
15
+ def set(client, query = {})
16
+ client.make_post_request(resource_url(client, __method__), query)
17
+ end
18
+ end
19
+ end
16
20
 
17
- def types(client, query = {})
21
+ class Communication < Bitrix24CloudApi::Base
22
+ class << self
23
+ def fields(client, query = {})
18
24
  client.make_get_request(resource_url(client, __method__), query)
19
25
  end
20
26
  end
21
27
  end
22
28
 
23
- class Localizations < Bitrix24CloudApi::Crm
29
+ class Multifield < Bitrix24CloudApi::Base
24
30
  class << self
25
- undef_method :delete, :fields, :get
31
+ def fields(client, query = {})
32
+ client.make_get_request(resource_url(client, __method__), query)
33
+ end
34
+ end
35
+ end
26
36
 
27
- def set(client, query = {})
28
- client.make_post_request(resource_url(client, __method__), query)
37
+ class Duplicate < Bitrix24CloudApi::Base
38
+ [:findbycomm].each do |action|
39
+ define_singleton_method(action) do |client, query = {}|
40
+ client.make_get_request(resource_url(client, action), query)
29
41
  end
30
42
  end
31
43
  end
32
44
 
33
- class Communication < Bitrix24CloudApi::Crm
34
- class << self
35
- undef_method :add, :delete, :update, :get, :list
45
+ class Stage < Bitrix24CloudApi::Base
46
+ [:list, :fields].each do |action|
47
+ define_singleton_method(action) do |client, query = {}|
48
+ client.make_get_request(resource_url(client, action), query)
49
+ end
36
50
  end
37
51
  end
38
52
 
39
- class Duplicate < Bitrix24CloudApi::Crm
40
- class << self
41
- undef_method :add, :delete, :update, :get, :list
53
+ class Enum < Bitrix24CloudApi::Base
54
+ [:ownertype, :contenttype, :activitytype, :activitypriority, :activitydirection,
55
+ :activitynotifytype, :fields].each do |action|
56
+ define_singleton_method(action) do |client, query = {}|
57
+ client.make_get_request(resource_url(client, action), query)
58
+ end
59
+ end
60
+ end
42
61
 
43
- def findbycomm(client, query = {})
62
+ class Settings < Bitrix24CloudApi::Base
63
+ class << self
64
+ def fields(client, query = {})
44
65
  client.make_get_request(resource_url(client, __method__), query)
45
66
  end
46
67
  end
47
68
  end
48
69
 
49
- class Enum < Bitrix24CloudApi::Crm
70
+ class Enumeration < Bitrix24CloudApi::Base
50
71
  class << self
51
- undef_method :add, :delete, :update, :get, :list
72
+ def fields(client, query = {})
73
+ client.make_get_request(resource_url(client, __method__), query)
74
+ end
52
75
  end
76
+ end
53
77
 
54
- [:ownertype, :contenttype, :activitytype, :activitypriority, :activitydirection,
55
- :activitynotifytype].each do |action|
78
+ class Paysystem < Bitrix24CloudApi::Base
79
+ [:list, :fields].each do |action|
80
+ define_singleton_method(action) do |client, query = {}|
81
+ client.make_get_request(resource_url(client, action), query)
82
+ end
83
+ end
84
+ end
85
+
86
+ class PersonType < Bitrix24CloudApi::Base
87
+ [:list, :fields].each do |action|
88
+ define_singleton_method(action) do |client, query = {}|
89
+ client.make_get_request(resource_url(client, action), query)
90
+ end
91
+ end
92
+ end
93
+
94
+ class Entity < Bitrix24CloudApi::Base
95
+ [:types, :items].each do |action|
56
96
  define_singleton_method(action) do |client, query = {}|
57
97
  client.make_get_request(resource_url(client, action), query)
58
98
  end
@@ -0,0 +1,9 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ class Address < Bitrix24CloudApi::Crm
4
+ class << self
5
+ undef_method :get
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ module DEAL_CATEGORY
4
+ def self.const_missing(c)
5
+ if c == :Stage
6
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
7
+ target_class.define_singleton_method(:resource_path) { "crm.dealcategory.#{c.downcase}" }
8
+ target_class
9
+ end
10
+ end
11
+ end
12
+
13
+ class DealCategory < Bitrix24CloudApi::Crm
14
+
15
+ [:status].each do |action|
16
+ define_singleton_method(action) do |client, query = {}|
17
+ client.make_get_request(resource_url(client, action), query)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ module EXTERNALCHANNEL
4
+ def self.const_missing(c)
5
+ if c == :Activity
6
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
7
+ target_class.define_singleton_method(:resource_path) { "crm.externalchannel.#{c.downcase}" }
8
+ target_class
9
+ end
10
+ end
11
+
12
+ class Connector < Bitrix24CloudApi::Base
13
+ class << self
14
+ def register(client, query = {})
15
+ client.make_post_request(resource_url(client, __method__), query)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ class Externalchannel < Bitrix24CloudApi::Base
22
+
23
+ [:company, :contact].each do |action|
24
+ define_singleton_method(action) do |client, query = {}|
25
+ client.make_get_request(resource_url(client, action), query)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,15 @@
1
1
  module Bitrix24CloudApi
2
2
  module CRM
3
+ module INVOICE
4
+ def self.const_missing(c)
5
+ if c == :Userfield
6
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
7
+ target_class.define_singleton_method(:resource_path) { "crm.invoice.#{c.downcase}" }
8
+ target_class
9
+ end
10
+ end
11
+ end
12
+
3
13
  class Invoice < Bitrix24CloudApi::Crm
4
14
  end
5
15
  end
@@ -0,0 +1,11 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ class LiveFeedMessage < Bitrix24CloudApi::Base
4
+ class << self
5
+ def add(client, query = {})
6
+ client.make_post_request(resource_url(client, __method__), query)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ class Measure < Bitrix24CloudApi::Crm
4
+ end
5
+ end
6
+ end
@@ -1,5 +1,25 @@
1
1
  module Bitrix24CloudApi
2
2
  module CRM
3
+ module PRODUCT
4
+ module PROPERTY
5
+ def self.const_missing(c)
6
+ if [:Settings, :Enumeration].any?{|x| x == c}
7
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
8
+ target_class.define_singleton_method(:resource_path) { "crm.product.property.#{c.downcase}" }
9
+ target_class
10
+ end
11
+ end
12
+ end
13
+
14
+ def self.const_missing(c)
15
+ if c == :Property
16
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
17
+ target_class.define_singleton_method(:resource_path) { "crm.product.#{c.downcase}" }
18
+ target_class
19
+ end
20
+ end
21
+ end
22
+
3
23
  class Product < Bitrix24CloudApi::Crm
4
24
  end
5
25
  end
@@ -0,0 +1,11 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ class ProductRow < Bitrix24CloudApi::Base
4
+ [:list, :fields].each do |action|
5
+ define_singleton_method(action) do |client, query = {}|
6
+ client.make_get_request(resource_url(client, action), query)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ class Property < Bitrix24CloudApi::Crm
4
+ class << self
5
+ def types(client, query = {})
6
+ client.make_get_request(resource_url(client, __method__), query)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,54 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ module REQUISITE
4
+ module PRESET
5
+ class Field < Bitrix24CloudApi::Crm
6
+ class << self
7
+ def availabletoadd(client, query = {})
8
+ client.make_get_request(resource_url(client, __method__), query)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ def self.const_missing(c)
15
+ if [:Userfield].any?{|x| x == c}
16
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
17
+ target_class.define_singleton_method(:resource_path) { "crm.requisite.#{c.downcase}" }
18
+ target_class
19
+ end
20
+ end
21
+
22
+ class Bankdetail < Bitrix24CloudApi::Crm
23
+ end
24
+
25
+ class Link < Bitrix24CloudApi::Base
26
+ [:fields, :get, :list].each do |action|
27
+ define_singleton_method(action) do |client, query = {}|
28
+ client.make_get_request(resource_url(client, action), query)
29
+ end
30
+ end
31
+
32
+ [:register, :unregister].each do |action|
33
+ define_singleton_method(action) do |client, query = {}|
34
+ client.make_post_request(resource_url(client, action), query)
35
+ end
36
+ end
37
+ end
38
+
39
+ class Preset < Bitrix24CloudApi::Crm
40
+ class << self
41
+ def countries(client, query = {})
42
+ client.make_get_request(resource_url(client, __method__), query)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ class Requisite < Bitrix24CloudApi::Crm
49
+ class << self
50
+ undef_method :update
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,16 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ module STATUS
4
+ def self.const_missing(c)
5
+ if c == :Entity
6
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
7
+ target_class.define_singleton_method(:resource_path) { "crm.status.#{c.downcase}" }
8
+ target_class
9
+ end
10
+ end
11
+ end
12
+
13
+ class Status < Bitrix24CloudApi::Crm
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ module USERFIELD
4
+ def self.const_missing(c)
5
+ if [:Settings, :Enumeration].any?{|x| x == c}
6
+ target_class = Bitrix24CloudApi::CRM.const_get(c)
7
+ target_class.define_singleton_method(:resource_path) { "crm.userfield.#{c.downcase}" }
8
+ target_class
9
+ end
10
+ end
11
+ end
12
+
13
+ class Userfield < Bitrix24CloudApi::Crm
14
+ class << self
15
+
16
+ def types(client, query = {})
17
+ client.make_get_request(resource_url(client, __method__), query)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ module Bitrix24CloudApi
2
+ module CRM
3
+ class Vat < Bitrix24CloudApi::Crm
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module B24
2
+ include Bitrix24CloudApi
3
+ end
4
+
5
+ module B24_CRM
6
+ include Bitrix24CloudApi::CRM
7
+ end
@@ -4,16 +4,22 @@ module Bitrix24CloudApi
4
4
  class Base
5
5
  require "httparty"
6
6
  extend Forwardable
7
- def_delegators 'self.class', :resource_url
7
+ def_delegators 'self.class', :resource_url, :to_query
8
8
 
9
9
  class << self
10
10
 
11
+ def to_query(params)
12
+ params.to_a.map { |x| "#{CGI.escape(x[0].to_s)}=#{CGI.escape(x[1].to_s)}" }.join("&")
13
+ end
14
+
11
15
  def resource_url(client, action)
12
- "#{client.api_endpoint + resource_path}.#{action}.#{client.extension}"
16
+ path = client.api_endpoint
17
+ path << "#{resource_path}." unless resource_path.empty?
18
+ path << "#{action}.#{client.extension}"
13
19
  end
14
20
 
15
- def resource_path
16
- name.gsub("Bitrix24CloudApi::", "").gsub("::", ".").downcase
21
+ def resource_path(exact_name = nil)
22
+ exact_name || name.gsub("Bitrix24CloudApi::", "").gsub("::", ".").downcase
17
23
  end
18
24
  end
19
25
  end
@@ -3,11 +3,12 @@ module Bitrix24CloudApi
3
3
  class Client < Base
4
4
  require 'oauth2'
5
5
 
6
+ B24_OAUTH_ENDPOINT = 'https://oauth.bitrix.info/oauth/token'
7
+
6
8
  attr_reader :endpoint, :access_token, :redirect_uri, :client_id, :client_secret, :scope, :oauth2client, :extension
7
9
  attr_writer :access_token
8
10
 
9
11
  def initialize(attrs = {})
10
- puts attrs[:extension]
11
12
  @extension = attrs[:extension] || "json"
12
13
  @endpoint = attrs[:endpoint]
13
14
  @access_token = attrs[:access_token]
@@ -27,47 +28,43 @@ module Bitrix24CloudApi
27
28
  def authorize_url
28
29
  return nil unless oauth2client
29
30
 
30
- oauth2client.auth_code.authorize_url(:redirect_uri => redirect_uri)
31
+ oauth2client.auth_code.authorize_url(:redirect_uri => redirect_uri, state: true)
31
32
  end
32
33
 
33
34
  def get_access_token(code)
34
35
  return nil unless oauth2client
35
36
 
36
- auth_token_query = {}
37
- auth_token_query[:client_id] = client_id
38
- auth_token_query[:client_secret] = client_secret
39
- auth_token_query[:grant_type] = "authorization_code"
40
- auth_token_query[:scope] = scope
41
- auth_token_query[:redirect_uri] = redirect_uri
42
- auth_token_path = oauth2client.options[:token_url] + "?#{to_query(auth_token_query)}"
37
+ auth_token_query = { client_id: client_id,
38
+ client_secret: client_secret,
39
+ grant_type: 'authorization_code',
40
+ code: code }
41
+ auth_token_path = "#{B24_OAUTH_ENDPOINT}?#{to_query(auth_token_query)}"
43
42
  oauth2client.options[:token_url] = auth_token_path
44
-
45
43
  begin
46
44
  token = oauth2client.auth_code.get_token(code, :redirect_uri => redirect_uri)
47
- token.params.merge({:access_token => token.token,
48
- :refresh_token => token.refresh_token,
49
- :expires_at => token.expires_at})
45
+ token.params.merge({ access_token: token.token,
46
+ refresh_token: token.refresh_token,
47
+ expires_at: token.expires_at })
50
48
  rescue OAuth2::Error
51
49
  return nil
52
50
  end
53
51
  end
54
52
 
55
- def refresh_token(refresh_token_hash)
53
+ def refresh_token(refresh_token)
56
54
  return nil unless oauth2client
57
55
 
58
- auth_token_query = {}
59
- auth_token_query[:client_id] = client_id
60
- auth_token_query[:client_secret] = client_secret
61
- auth_token_query[:grant_type] = 'refresh_token'
62
- auth_token_query[:refresh_token] = refresh_token_hash
63
- auth_token_path = "/oauth/token?#{to_query(auth_token_query)}"
56
+ auth_token_query = { client_id: client_id,
57
+ client_secret: client_secret,
58
+ grant_type: 'refresh_token',
59
+ refresh_token: refresh_token }
60
+ auth_token_path = "#{B24_OAUTH_ENDPOINT}?#{to_query(auth_token_query)}"
64
61
  oauth2client.options[:token_url] = auth_token_path
65
62
 
66
63
  begin
67
64
  token = oauth2client.get_token(auth_token_query)
68
- token.params.merge({:access_token => token.token,
69
- :refresh_token => token.refresh_token,
70
- :expires_at => token.expires_at})
65
+ token.params.merge({ access_token: token.token,
66
+ refresh_token: token.refresh_token,
67
+ expires_at: token.expires_at })
71
68
  rescue OAuth2::Error
72
69
  return false
73
70
  end
@@ -75,13 +72,17 @@ module Bitrix24CloudApi
75
72
 
76
73
  def make_get_request(path, params = {})
77
74
  params.merge!(auth: access_token)
78
- response = HTTParty.get(path, query: params)
75
+ response = HTTParty.get(path,
76
+ query: params,
77
+ query_string_normalizer: ->(query) { Bitrix24CloudApi::HashConversions.to_params(query) })
79
78
  check_response(response)
80
79
  end
81
80
 
82
81
  def make_post_request(path, params = {})
83
- params.merge!(auth: access_token)
84
- response = HTTParty.post(path, query: params)
82
+ response = HTTParty.post(path,
83
+ body: params,
84
+ query: { auth: access_token },
85
+ query_string_normalizer: ->(query) { Bitrix24CloudApi::HashConversions.to_params(query) })
85
86
  check_response(response)
86
87
  end
87
88