primecontext-ruby 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55905fda238f55fa217eeed5dd2b96ddedd5816f
4
+ data.tar.gz: 01e0c3597d416e4feb3e7940317372d894a4757e
5
+ SHA512:
6
+ metadata.gz: 1411f3507241b16d5badc2e33c51fd3d67c9541a9b50107124b6d7e543c3995b2f6fbb088a6356a23b85468c47435a73f3b0d60281553a886ae4d28aaea7d075
7
+ data.tar.gz: 139d698d8d3a45a33c4f49eea28d9dadc2f547a1d0f9f15c91ff3ba6864fcddc4ebdfbf8f6caea038e6b675857dd15fa0734ca6d762303bd13c82927dc426b2b
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aleksey Korchagin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ A ruby wrapper for [Primecontext CRM](https://beta.primecontext.ru).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ require 'primecontext/api'
2
+
3
+ module Primecontext
4
+
5
+ def self.default_options
6
+ {
7
+ api_url: 'https://beta.primecontext.ru/api/crm/new-record/',
8
+ user_id: 0,
9
+ secret_key: '00000000000000000000000000000000'
10
+ }
11
+ end
12
+
13
+ end
@@ -0,0 +1,36 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+
5
+ module Primecontext
6
+
7
+ class Api
8
+ attr_reader :options, :data
9
+
10
+ def initialize(options = {})
11
+ @options = Primecontext::default_options.merge(options)
12
+ @data = { user_id: @options[:user_id] }
13
+ end
14
+
15
+ def new_record(data = {})
16
+ @data = @data.merge(Hash[data.map{ |(k,v)| [k.to_sym, v] }])
17
+ @data.merge!({ sign: generate_sign(@data) })
18
+ send_request(@data)
19
+ end
20
+
21
+ def generate_sign(data)
22
+ data_str = data.sort.join.mb_chars.downcase
23
+ digest = OpenSSL::Digest.new 'sha256'
24
+ OpenSSL::HMAC.hexdigest digest, @options[:secret_key], data_str
25
+ end
26
+
27
+ def send_request(data)
28
+ uri = URI.parse(@options[:api_url])
29
+ http = Net::HTTP.new(uri.host, uri.port)
30
+ http.use_ssl = true
31
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
+ http.request_post(uri.request_uri, URI.encode_www_form(data))
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,3 @@
1
+ module Primecontext
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: primecontext-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aleksey Korchagin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby gem fot Primecontext CRM Api
14
+ email: lexx-kor@ya.ru
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/primecontext/api.rb
20
+ - lib/primecontext/version.rb
21
+ - lib/primecontext-ruby.rb
22
+ - LICENSE
23
+ - Rakefile
24
+ - README.md
25
+ homepage: https://github.com/lexxor/primecontext-ruby
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.14
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Ruby gem for Primecontext CRM Api
49
+ test_files: []