sugarcrb 0.0.3 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c280020944c65e66cfd5370c27d5a62db8222e1
4
- data.tar.gz: e6fe013dfa212d24dc5af21278c0ab2a2791c72d
3
+ metadata.gz: 62747b16d9d32c88b2aab62091931e1ea541cc9d
4
+ data.tar.gz: 24c48100141d948960f14fe4285272c913b036cb
5
5
  SHA512:
6
- metadata.gz: a37daebed6df401edd681af62d8abaa73f6b34847dbb15688f3c3f1e3e7116597b10b3406fac5e48fe08519851ce1cf315af03c466d97165201891dce72c508c
7
- data.tar.gz: 8f77b7f83083a49759aa3722ca2f2a7ffada3ec2b6dbec37ad525d1ed0576315b8ce4e5636550826483d044b94e8ea56a3cc95ba0003f6086d6bed531b064bad
6
+ metadata.gz: 1dad9e0056d566f256f40f38d87894e573a47e02d7524119540fc3409b85cd20555d9b6c4dc8fa81f5e24c7a3c73174268a91cab150a449cf1ddecff898f51f9
7
+ data.tar.gz: 0fda6943664851de0fc460446fd81762dbd27e1446e6d46c4f2a5f9396be4b650f00578bd69847a87f03be63ca3121671ed0b619be51cc065edceefb989472e4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at pedroalbertose007@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sugarcrb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 betobaz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Sugarcrb
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sugarcrb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sugarcrb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sugarcrb
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sugarcrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
 
3
- Rake::TestTask.new do |t|
4
- t.libs << 'test'
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
5
8
  end
6
9
 
7
- desc "Run tests"
8
10
  task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sugarcrb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Sugarcrb
2
+ VERSION = "0.1.1"
3
+ end
data/lib/sugarcrb.rb CHANGED
@@ -1,48 +1,34 @@
1
+ require "sugarcrb/version"
1
2
  require 'rest-client'
2
- class Sugarcrb
3
3
 
4
- def initialize(host, username, password, platform, client_id, client_secret)
5
- # Instance variables
6
- @host = host
7
- @username = username
8
- @password = password
9
- @platform = platform
10
- @client_secret = client_secret
11
- @client_id = client_id
12
- @access_token = ""
13
- @refresh_token = ""
14
- end
15
-
16
- attr_accessor :username
17
- attr_accessor :access_token
18
- attr_accessor :refresh_token
4
+ module Sugarcrb
5
+ class Sugarcrb
19
6
 
20
- def oauth2_token (refresh = false)
21
- data = {
22
- "grant_type": "password",
23
- "client_id": @client_id,
24
- "client_secret": @client_secret,
25
- "username": @username,
26
- "password": @password,
27
- "platform": @platform
28
- }
29
- response = RestClient.post "#{@host}/rest/v10/oauth2/token", data
30
- response_json = JSON.load(response)
31
- if (response.code == 200) then
32
- @access_token = response_json['access_token']
33
- @refresh_token = response_json['refresh_token']
7
+ def initialize(host, username, password, platform, client_id, client_secret)
8
+ # Instance variables
9
+ @host = host
10
+ @username = username
11
+ @password = password
12
+ @platform = platform
13
+ @client_secret = client_secret
14
+ @client_id = client_id
15
+ @access_token = ""
16
+ @refresh_token = ""
34
17
  end
35
- return response
36
- end
37
18
 
38
- def oauth2_refresh_token
39
- data = {
40
- "grant_type": "refresh_token",
41
- "refresh_token": @refresh_token,
42
- "client_id": @client_id,
43
- "client_secret": @client_secret,
44
- }
45
- begin
19
+ attr_accessor :username
20
+ attr_accessor :access_token
21
+ attr_accessor :refresh_token
22
+
23
+ def oauth2_token (refresh = false)
24
+ data = {
25
+ "grant_type": "password",
26
+ "client_id": @client_id,
27
+ "client_secret": @client_secret,
28
+ "username": @username,
29
+ "password": @password,
30
+ "platform": @platform
31
+ }
46
32
  response = RestClient.post "#{@host}/rest/v10/oauth2/token", data
47
33
  response_json = JSON.load(response)
48
34
  if (response.code == 200) then
@@ -50,27 +36,46 @@ class Sugarcrb
50
36
  @refresh_token = response_json['refresh_token']
51
37
  end
52
38
  return response
53
- rescue RestClient::Unauthorized => err
54
- return self.oauth2_token
55
39
  end
56
- end
57
40
 
58
- def call (method, endpoint, data = false, reintents = 0)
59
- begin
60
- response = case method
61
- when "post" then RestClient.post "#{@host}/rest/v10/#{endpoint}", data, headers={"OAuth-Token" => @access_token}
62
- when "get" then RestClient.get "#{@host}/rest/v10/#{endpoint}", headers={"OAuth-Token" => @access_token}
63
- when "put" then RestClient.put "#{@host}/rest/v10/#{endpoint}", data, headers={"OAuth-Token" => @access_token}
64
- when "delete" then RestClient.delete "#{@host}/rest/v10/#{endpoint}", headers={"OAuth-Token" => @access_token}
41
+ def oauth2_refresh_token
42
+ data = {
43
+ "grant_type": "refresh_token",
44
+ "refresh_token": @refresh_token,
45
+ "client_id": @client_id,
46
+ "client_secret": @client_secret,
47
+ }
48
+ begin
49
+ response = RestClient.post "#{@host}/rest/v10/oauth2/token", data
50
+ response_json = JSON.load(response)
51
+ if (response.code == 200) then
52
+ @access_token = response_json['access_token']
53
+ @refresh_token = response_json['refresh_token']
54
+ end
55
+ return response
56
+ rescue RestClient::Unauthorized => err
57
+ return self.oauth2_token
65
58
  end
59
+ end
66
60
 
67
- return response
68
- rescue RestClient::Unauthorized => err
69
- if reintents < 3 then
70
- self.oauth2_refresh_token
71
- reintents = reintents + 1
72
- self.call(method, endpoint, data, reintents)
61
+ def call (method, endpoint, data = false, reintents = 0)
62
+ begin
63
+ response = case method
64
+ when "post" then RestClient.post "#{@host}/rest/v10/#{endpoint}", data, headers={"OAuth-Token" => @access_token}
65
+ when "get" then RestClient.get "#{@host}/rest/v10/#{endpoint}", headers={"OAuth-Token" => @access_token}
66
+ when "put" then RestClient.put "#{@host}/rest/v10/#{endpoint}", data, headers={"OAuth-Token" => @access_token}
67
+ when "delete" then RestClient.delete "#{@host}/rest/v10/#{endpoint}", headers={"OAuth-Token" => @access_token}
68
+ end
69
+
70
+ return response
71
+ rescue RestClient::Unauthorized => err
72
+ if reintents < 3 then
73
+ self.oauth2_refresh_token
74
+ reintents = reintents + 1
75
+ self.call(method, endpoint, data, reintents)
76
+ end
73
77
  end
74
78
  end
75
79
  end
80
+
76
81
  end
data/sugarcrb.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sugarcrb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sugarcrb"
8
+ spec.version = Sugarcrb::VERSION
9
+ spec.authors = ["betobaz"]
10
+ spec.email = ["pedroalbertose007@gmail.com"]
11
+
12
+ spec.summary = "Sugarcrm client"
13
+ spec.description = "Gem to use create a cliente to SugarCRM by API rest V10"
14
+ spec.homepage = "https://rubygems.org/gems/sugarcrb"
15
+ spec.license = "MIT"
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'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_runtime_dependency 'rest-client', '~> 1.8'
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.14"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+ spec.add_development_dependency 'webmock', '~> 2.3'
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Pedro Bazan
7
+ - betobaz
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: webmock
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -39,19 +81,29 @@ dependencies:
39
81
  - !ruby/object:Gem::Version
40
82
  version: '2.3'
41
83
  description: Gem to use create a cliente to SugarCRM by API rest V10
42
- email: pedrob@merxbp.com
84
+ email:
85
+ - pedroalbertose007@gmail.com
43
86
  executables: []
44
87
  extensions: []
45
88
  extra_rdoc_files: []
46
89
  files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
47
96
  - Rakefile
97
+ - bin/console
98
+ - bin/setup
48
99
  - lib/sugarcrb.rb
49
- - test/test_helper.rb
50
- - test/test_sugarcrb.rb
100
+ - lib/sugarcrb/version.rb
101
+ - sugarcrb.gemspec
51
102
  homepage: https://rubygems.org/gems/sugarcrb
52
103
  licenses:
53
104
  - MIT
54
- metadata: {}
105
+ metadata:
106
+ allowed_push_host: https://rubygems.org
55
107
  post_install_message:
56
108
  rdoc_options: []
57
109
  require_paths:
@@ -72,6 +124,4 @@ rubygems_version: 2.4.6
72
124
  signing_key:
73
125
  specification_version: 4
74
126
  summary: Sugarcrm client
75
- test_files:
76
- - test/test_sugarcrb.rb
77
- - test/test_helper.rb
127
+ test_files: []
data/test/test_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require "minitest/reporters"
2
- require 'webmock/minitest'
3
- Minitest::Reporters.use!
@@ -1,194 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'sugarcrb'
3
-
4
- describe "Sugarcrm" do
5
-
6
- before do
7
- @sugarcrm = Sugarcrb.new("http://lowes.merxbp.loc","admin","Lowes2017","tests","sugar","")
8
- end
9
-
10
- describe "Cuando se inicializa la Clase" do
11
- it "Debe de tener valores" do
12
- assert_equal "admin", @sugarcrm.username
13
- end
14
- end
15
-
16
- describe "Cuando hace login" do
17
- it "Debe de obtener respuesta valida" do
18
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
19
- .with(body: {"grant_type":"password","client_id":"sugar","client_secret":"","username":"admin","password":"Lowes2017","platform":"tests"})
20
- .to_return(status: 200, body: '{"access_token":"AAA","refresh_token":"RRR"}', headers: {})
21
-
22
- response = JSON.load(@sugarcrm.oauth2_token)
23
- assert_equal "AAA", response['access_token']
24
- assert_equal "RRR", response['refresh_token']
25
- assert_equal "AAA", @sugarcrm.access_token
26
- assert_equal "RRR", @sugarcrm.refresh_token
27
- end
28
-
29
- it "Debe de obtener respuesta valida" do
30
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
31
- .to_return(status: 401, body: '{"error":"need_login","error_message":"Debe especificar un usuario y contrase\u00f1a v\u00e1lidos."}', headers: {})
32
-
33
- assert_raises RuntimeError do
34
- @sugarcrm.oauth2_token
35
- end
36
-
37
- assert_empty @sugarcrm.instance_variable_get("@access_token")
38
- assert_empty @sugarcrm.instance_variable_get("@refresh_token")
39
- end
40
-
41
- it "Debe de obtener respuesta valida" do
42
- @sugarcrm.refresh_token = "RRR"
43
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
44
- .with(body: {"grant_type":"refresh_token","refresh_token":"RRR","client_id":"sugar","client_secret":""})
45
- .to_return(status: 200, body: '{"access_token":"AA1","refresh_token":"RR1"}', headers: {})
46
-
47
- response = JSON.load(@sugarcrm.oauth2_refresh_token)
48
- assert_equal "AA1", response['access_token']
49
- assert_equal "RR1", response['refresh_token']
50
- assert_equal "AA1", @sugarcrm.access_token
51
- assert_equal "RR1", @sugarcrm.refresh_token
52
- end
53
-
54
- end
55
-
56
- describe "Cuando llama el api" do
57
- it "Debe de crear un registro con peticion valida" do
58
- @sugarcrm.access_token = "AAA"
59
- @sugarcrm.refresh_token = "RRR"
60
-
61
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
62
- .with(headers: { 'OAuth-Token' => "AAA" })
63
- .to_return(status: 200, body: '{"id":"SUGARID","name":"Account name"}', headers: {})
64
-
65
- response = JSON.load(@sugarcrm.call("post", "Accounts",{
66
- "name" => "Account name"
67
- }))
68
-
69
- assert_equal "SUGARID", response['id']
70
- assert_equal "Account name", response['name']
71
- end
72
-
73
- it "Debe de crear un registro con peticion invalida por token expirado" do
74
- @sugarcrm.access_token = "AAA"
75
- @sugarcrm.refresh_token = "RRR"
76
-
77
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
78
- .with(headers: { 'OAuth-Token' => "AAA" })
79
- .to_return(status: 401, body: '{"error":"invalid_grant","error_message":"The access token provided is invalid."}', headers: {})
80
-
81
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
82
- .with(body: {"grant_type":"refresh_token","refresh_token":"RRR","client_id":"sugar","client_secret":""})
83
- .to_return(status: 200, body: '{"access_token":"AA1","refresh_token":"RR1"}', headers: {})
84
-
85
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
86
- .with(headers: { 'OAuth-Token' => "AA1" })
87
- .to_return(status: 200, body: '{"id":"SUGARID","name":"Account name"}', headers: {})
88
-
89
- response = JSON.load(@sugarcrm.call("post", "Accounts",{
90
- "name" => "Account name"
91
- }))
92
-
93
- assert_equal "SUGARID", response['id']
94
- assert_equal "Account name", response['name']
95
- assert_equal "AA1", @sugarcrm.access_token
96
- assert_equal "RR1", @sugarcrm.refresh_token
97
- end
98
-
99
- it "Debe de crear un registro con peticion invalida por token expirado y refresh_token expirado" do
100
- @sugarcrm.access_token = "AAA"
101
- @sugarcrm.refresh_token = "RRR"
102
-
103
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
104
- .with(headers: { 'OAuth-Token' => "AAA" })
105
- .to_return(status: 401, body: '{"error":"invalid_grant","error_message":"The access token provided is invalid."}', headers: {})
106
-
107
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
108
- .with(body: {"grant_type":"refresh_token","refresh_token":"RRR","client_id":"sugar","client_secret":""})
109
- .to_return(status: 401, body: '{"error":"need_login","error_message":"Debe especificar un usuario y contrase\u00f1a v\u00e1lidos."}', headers: {})
110
-
111
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
112
- .with(body: {"grant_type":"password","client_id":"sugar","client_secret":"","username":"admin","password":"Lowes2017","platform":"tests"})
113
- .to_return(status: 200, body: '{"access_token":"AA2","refresh_token":"RR2"}', headers: {})
114
-
115
- stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
116
- .with(headers: { 'OAuth-Token' => "AA2" })
117
- .to_return(status: 200, body: '{"id":"SUGARID","name":"Account name"}', headers: {})
118
-
119
- response = JSON.load(@sugarcrm.call("post", "Accounts",{
120
- "name" => "Account name"
121
- }))
122
-
123
- assert_equal "SUGARID", response['id']
124
- assert_equal "Account name", response['name']
125
- assert_equal "AA2", @sugarcrm.access_token
126
- assert_equal "RR2", @sugarcrm.refresh_token
127
- end
128
-
129
- it "Debe de listar un registro con peticion valida empty" do
130
- @sugarcrm.access_token = "AAA"
131
-
132
- stub_request(:get, "http://lowes.merxbp.loc/rest/v10/Accounts")
133
- .with(headers: { 'OAuth-Token' => "AAA" })
134
- .to_return(status: 200, body: '{"next_offset":-1,"records":[]}', headers: {})
135
-
136
- response = JSON.load(@sugarcrm.call("get", "Accounts"))
137
-
138
- assert_equal -1, response['next_offset']
139
- assert_equal 0, response['records'].length
140
- end
141
-
142
- it "Debe de listar un registro con peticion valida con un elemento" do
143
- @sugarcrm.access_token = "AAA"
144
-
145
- stub_request(:get, "http://lowes.merxbp.loc/rest/v10/Accounts")
146
- .with(headers: { 'OAuth-Token' => "AAA" })
147
- .to_return(status: 200, body: '{"next_offset":20,"records":[{"id":"AAA","name":"Account Name"}]}', headers: {})
148
-
149
- response = JSON.load(@sugarcrm.call("get", "Accounts"))
150
-
151
- assert_equal 20, response['next_offset']
152
- assert_equal 1, response['records'].length
153
- end
154
-
155
- it "Debe de obtener un registro con peticion valida " do
156
- @sugarcrm.access_token = "AAA"
157
-
158
- stub_request(:get, "http://lowes.merxbp.loc/rest/v10/Accounts/AAA")
159
- .with(headers: { 'OAuth-Token' => "AAA" })
160
- .to_return(status: 200, body: '{"id":"AAA","name":"Account Name"}', headers: {})
161
-
162
- response = JSON.load(@sugarcrm.call("get", "Accounts/AAA"))
163
-
164
- assert_equal "AAA", response['id']
165
- assert_equal "Account Name", response['name']
166
- end
167
-
168
- it "Debe de actualizar un registro con peticion valida " do
169
- @sugarcrm.access_token = "AAA"
170
-
171
- stub_request(:put, "http://lowes.merxbp.loc/rest/v10/Accounts/AAA")
172
- .with(headers: { 'OAuth-Token' => "AAA" })
173
- .to_return(status: 200, body: '{"id":"AAA","name":"Account Name Change"}', headers: {})
174
-
175
- response = JSON.load(@sugarcrm.call("put", "Accounts/AAA", {"name"=>"Account Name Change"}))
176
-
177
- assert_equal "AAA", response['id']
178
- assert_equal "Account Name Change", response['name']
179
- end
180
-
181
- it "Debe de eliminar un registro con peticion valida " do
182
- @sugarcrm.access_token = "AAA"
183
-
184
- stub_request(:delete, "http://lowes.merxbp.loc/rest/v10/Accounts/AAA")
185
- .with(headers: { 'OAuth-Token' => "AAA" })
186
- .to_return(status: 200, headers: {})
187
-
188
- response = @sugarcrm.call("delete", "Accounts/AAA")
189
- assert_equal 200, response.code
190
- end
191
- end
192
-
193
-
194
- end