bitrix24_cloud_api 0.1.0 → 0.1.2

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.
@@ -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
@@ -80,8 +77,7 @@ module Bitrix24CloudApi
80
77
  end
81
78
 
82
79
  def make_post_request(path, params = {})
83
- params.merge!(auth: access_token)
84
- response = HTTParty.post(path, query: params)
80
+ response = HTTParty.post(path, body: params, query: {auth: access_token})
85
81
  check_response(response)
86
82
  end
87
83
 
@@ -0,0 +1,62 @@
1
+ module Bitrix24CloudApi
2
+ module COMMON_METHODS
3
+ class User < Base
4
+ [:admin, :access, :get].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
+
10
+ class << self
11
+ def resource_path
12
+ "user"
13
+ end
14
+ end
15
+ end
16
+
17
+ class App < Base
18
+ class << self
19
+
20
+ def info(client)
21
+ client.make_get_request(resource_url(client, __method__))
22
+ end
23
+
24
+ def resource_path
25
+ "app"
26
+ end
27
+ end
28
+ end
29
+
30
+ class Event < Base
31
+ [:bind, :unbind, :get].each do |action|
32
+ define_singleton_method(action) do |client, query = {}|
33
+ client.make_get_request(resource_url(client, action), query)
34
+ end
35
+ end
36
+
37
+ class << self
38
+ def resource_path
39
+ "event"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ class CommonMethods < Base
46
+ METHODS_SCOPE = [:methods, :scope, :batch, :access_name, :events]
47
+
48
+ METHODS_SCOPE.each do |action|
49
+ define_singleton_method(action) do |client, query = {}|
50
+ client.make_get_request(resource_url(client, action), query)
51
+ end
52
+ end
53
+
54
+ class << self
55
+ def resource_path
56
+ name = super
57
+ name.gsub("commonmethods", "")
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -8,7 +8,6 @@ module Bitrix24CloudApi
8
8
  end
9
9
  end
10
10
 
11
-
12
11
  [:get, :list, :fields].each do |action|
13
12
  define_singleton_method(action) do |client, query = {}|
14
13
  client.make_get_request(resource_url(client, action), query)
@@ -18,15 +17,26 @@ module Bitrix24CloudApi
18
17
  end
19
18
 
20
19
  require "bitrix24_cloud_api/CRM/additional_entities"
20
+ require "bitrix24_cloud_api/CRM/address"
21
21
  require "bitrix24_cloud_api/CRM/activity"
22
22
  require "bitrix24_cloud_api/CRM/catalog"
23
23
  require "bitrix24_cloud_api/CRM/company"
24
24
  require "bitrix24_cloud_api/CRM/contact"
25
25
  require "bitrix24_cloud_api/CRM/currency"
26
26
  require "bitrix24_cloud_api/CRM/deal"
27
+ require "bitrix24_cloud_api/CRM/deal_category"
28
+ require "bitrix24_cloud_api/CRM/externalchannel"
27
29
  require "bitrix24_cloud_api/CRM/invoice"
28
30
  require "bitrix24_cloud_api/CRM/invoice_status"
29
31
  require "bitrix24_cloud_api/CRM/lead"
32
+ require "bitrix24_cloud_api/CRM/live_feed_message"
33
+ require "bitrix24_cloud_api/CRM/measure"
30
34
  require "bitrix24_cloud_api/CRM/product"
35
+ require "bitrix24_cloud_api/CRM/product_row"
31
36
  require "bitrix24_cloud_api/CRM/product_section"
37
+ require "bitrix24_cloud_api/CRM/property"
38
+ require "bitrix24_cloud_api/CRM/requisite"
39
+ require "bitrix24_cloud_api/CRM/status"
40
+ require "bitrix24_cloud_api/CRM/vat"
32
41
  require "bitrix24_cloud_api/CRM/quote"
42
+ require "bitrix24_cloud_api/CRM/userfield"
@@ -1,3 +1,3 @@
1
1
  module Bitrix24CloudApi
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,8 +1,9 @@
1
1
  require "bitrix24_cloud_api/base"
2
2
  require "bitrix24_cloud_api/client"
3
+ require "bitrix24_cloud_api/common_methods/common_methods"
3
4
  require "bitrix24_cloud_api/crm"
5
+ require "bitrix24_cloud_api/aliases"
4
6
  require "bitrix24_cloud_api/version"
5
7
 
6
8
  module Bitrix24CloudApi
7
- # Your code goes here...
8
9
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitrix24_cloud_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viacheslav Gruzdov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.7
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,33 +81,47 @@ dependencies:
53
81
  - !ruby/object:Gem::Version
54
82
  version: '3.0'
55
83
  - !ruby/object:Gem::Dependency
56
- name: oauth2
84
+ name: webmock
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
- version: '1.1'
89
+ version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
- version: '1.1'
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: httparty
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: shoulda-matchers
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - "~>"
74
116
  - !ruby/object:Gem::Version
75
- version: 0.13.7
117
+ version: '2.0'
76
118
  type: :development
77
119
  prerelease: false
78
120
  version_requirements: !ruby/object:Gem::Requirement
79
121
  requirements:
80
122
  - - "~>"
81
123
  - !ruby/object:Gem::Version
82
- version: 0.13.7
124
+ version: '2.0'
83
125
  description: Bitrix24 REST API wrapper (for only cloud version)
84
126
  email:
85
127
  - lucky-@mail.ru
@@ -88,13 +130,6 @@ extensions: []
88
130
  extra_rdoc_files: []
89
131
  files:
90
132
  - ".gitignore"
91
- - ".idea/.name"
92
- - ".idea/.rakeTasks"
93
- - ".idea/bitrix24_cloud_api.iml"
94
- - ".idea/misc.xml"
95
- - ".idea/modules.xml"
96
- - ".idea/vcs.xml"
97
- - ".idea/workspace.xml"
98
133
  - ".rspec"
99
134
  - ".travis.yml"
100
135
  - CODE_OF_CONDUCT.md
@@ -108,19 +143,32 @@ files:
108
143
  - lib/bitrix24_cloud_api.rb
109
144
  - lib/bitrix24_cloud_api/CRM/activity.rb
110
145
  - lib/bitrix24_cloud_api/CRM/additional_entities.rb
146
+ - lib/bitrix24_cloud_api/CRM/address.rb
111
147
  - lib/bitrix24_cloud_api/CRM/catalog.rb
112
148
  - lib/bitrix24_cloud_api/CRM/company.rb
113
149
  - lib/bitrix24_cloud_api/CRM/contact.rb
114
150
  - lib/bitrix24_cloud_api/CRM/currency.rb
115
151
  - lib/bitrix24_cloud_api/CRM/deal.rb
152
+ - lib/bitrix24_cloud_api/CRM/deal_category.rb
153
+ - lib/bitrix24_cloud_api/CRM/externalchannel.rb
116
154
  - lib/bitrix24_cloud_api/CRM/invoice.rb
117
155
  - lib/bitrix24_cloud_api/CRM/invoice_status.rb
118
156
  - lib/bitrix24_cloud_api/CRM/lead.rb
157
+ - lib/bitrix24_cloud_api/CRM/live_feed_message.rb
158
+ - lib/bitrix24_cloud_api/CRM/measure.rb
119
159
  - lib/bitrix24_cloud_api/CRM/product.rb
160
+ - lib/bitrix24_cloud_api/CRM/product_row.rb
120
161
  - lib/bitrix24_cloud_api/CRM/product_section.rb
162
+ - lib/bitrix24_cloud_api/CRM/property.rb
121
163
  - lib/bitrix24_cloud_api/CRM/quote.rb
164
+ - lib/bitrix24_cloud_api/CRM/requisite.rb
165
+ - lib/bitrix24_cloud_api/CRM/status.rb
166
+ - lib/bitrix24_cloud_api/CRM/userfield.rb
167
+ - lib/bitrix24_cloud_api/CRM/vat.rb
168
+ - lib/bitrix24_cloud_api/aliases.rb
122
169
  - lib/bitrix24_cloud_api/base.rb
123
170
  - lib/bitrix24_cloud_api/client.rb
171
+ - lib/bitrix24_cloud_api/common_methods/common_methods.rb
124
172
  - lib/bitrix24_cloud_api/crm.rb
125
173
  - lib/bitrix24_cloud_api/version.rb
126
174
  homepage: https://github.com/nononoy/bitrix24_cloud_api
@@ -148,4 +196,3 @@ signing_key:
148
196
  specification_version: 4
149
197
  summary: Bitrix24 REST API on Ruby
150
198
  test_files: []
151
- has_rdoc:
data/.idea/.name DELETED
@@ -1 +0,0 @@
1
- bitrix24_cloud_api
data/.idea/.rakeTasks DELETED
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Settings><!--This file was automatically generated by Ruby plugin.
3
- You are allowed to:
4
- 1. Remove rake task
5
- 2. Add existing rake tasks
6
- To add existing rake tasks automatically delete this file and reload the project.
7
- --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
@@ -1,19 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="FacetManager">
4
- <facet type="gem" name="Ruby Gem">
5
- <configuration>
6
- <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
- <option name="GEM_APP_TEST_PATH" value="" />
8
- <option name="GEM_APP_LIB_PATH" value="" />
9
- </configuration>
10
- </facet>
11
- </component>
12
- <component name="NewModuleRootManager">
13
- <content url="file://$MODULE_DIR$" />
14
- <orderEntry type="jdk" jdkName="RVM: ruby-2.3.1 [global]" jdkType="RUBY_SDK" />
15
- <orderEntry type="sourceFolder" forTests="false" />
16
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.12.4, RVM: ruby-2.3.1 [global]) [gem]" level="application" />
17
- <orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, RVM: ruby-2.3.1 [global]) [gem]" level="application" />
18
- </component>
19
- </module>