Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ee8717a9
Commit
ee8717a9
authored
Sep 10, 2019
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address suggestions from last code review
Subscription Portal client and Create Lead service were refactored
parent
1cf4977d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
15 deletions
+17
-15
ee/app/services/gitlab_subscriptions/create_lead_service.rb
ee/app/services/gitlab_subscriptions/create_lead_service.rb
+4
-4
ee/lib/gitlab/subscription_portal/client.rb
ee/lib/gitlab/subscription_portal/client.rb
+10
-8
ee/spec/lib/gitlab/subscription_portal/client_spec.rb
ee/spec/lib/gitlab/subscription_portal/client_spec.rb
+3
-3
No files found.
ee/app/services/gitlab_subscriptions/create_lead_service.rb
View file @
ee8717a9
...
...
@@ -3,18 +3,18 @@
module
GitlabSubscriptions
class
CreateLeadService
def
execute
(
company_params
)
response
=
subscription_app_
client
.
generate_trial
(
company_params
)
response
=
client
.
generate_trial
(
company_params
)
if
response
.
success
if
response
[
:success
]
{
success:
true
}
else
{
success:
false
,
errors:
response
.
data
&
.
errors
}
{
success:
false
,
errors:
response
[
:data
]
&
.
errors
}
end
end
private
def
subscription_app_
client
def
client
Gitlab
::
SubscriptionPortal
::
Client
.
new
end
end
...
...
ee/lib/gitlab/subscription_portal/client.rb
View file @
ee8717a9
...
...
@@ -4,9 +4,11 @@ module Gitlab
module
SubscriptionPortal
class
Client
def
generate_trial
(
params
)
parse_response
(
Gitlab
::
HTTP
.
post
(
"
#{
base_url
}
/trials"
,
body:
params
.
to_json
,
headers:
headers
))
response
=
Gitlab
::
HTTP
.
post
(
"
#{
base_url
}
/trials"
,
body:
params
.
to_json
,
headers:
headers
)
parse_response
(
response
)
rescue
*
Gitlab
::
HTTP
::
HTTP_ERRORS
=>
e
{
success:
false
,
data:
{
errors:
e
.
message
}
}
end
private
...
...
@@ -25,16 +27,16 @@ module Gitlab
end
def
parse_response
(
http_response
)
response
=
Hashie
::
Mash
.
new
(
success:
false
)
response
=
{
success:
false
}
case
http_response
.
response
when
Net
::
HTTPSuccess
response
.
success
=
true
response
.
data
=
JSON
.
parse
(
http_response
.
body
)
rescue
nil
response
[
:success
]
=
true
response
[
:data
]
=
http_response
.
parsed_response
when
Net
::
HTTPUnprocessableEntity
response
.
data
=
JSON
.
parse
(
http_response
.
body
)
rescue
nil
response
[
:data
]
=
http_response
.
parsed_response
else
response
.
data
=
{
errors:
"HTTP status code:
#{
http_response
.
code
}
"
}
response
[
:data
]
=
{
errors:
"HTTP status code:
#{
http_response
.
code
}
"
}
end
response
...
...
ee/spec/lib/gitlab/subscription_portal/client_spec.rb
View file @
ee8717a9
...
...
@@ -17,7 +17,7 @@ describe Gitlab::SubscriptionPortal::Client do
it
'has a successful status'
do
allow
(
Gitlab
::
HTTP
).
to
receive
(
:post
).
and_return
(
httparty_response
)
expect
(
subject
.
success
).
to
eq
(
true
)
expect
(
subject
[
:success
]
).
to
eq
(
true
)
end
end
...
...
@@ -27,7 +27,7 @@ describe Gitlab::SubscriptionPortal::Client do
it
'has a unprocessable entity status'
do
allow
(
Gitlab
::
HTTP
).
to
receive
(
:post
).
and_return
(
httparty_response
)
expect
(
subject
.
success
).
to
eq
(
false
)
expect
(
subject
[
:success
]
).
to
eq
(
false
)
end
end
...
...
@@ -37,7 +37,7 @@ describe Gitlab::SubscriptionPortal::Client do
it
'has a server error status'
do
allow
(
Gitlab
::
HTTP
).
to
receive
(
:post
).
and_return
(
httparty_response
)
expect
(
subject
.
success
).
to
eq
(
false
)
expect
(
subject
[
:success
]
).
to
eq
(
false
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment