-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compatibility with CivciCRM API v4 (#36)
* Compatibility with CivciCRM API v4 * Change API version variable * Show display name instead of email in contact displaoy name * Added name and nickname parsers * Added tests for API v4 * Pinning chrome version to v119 * Improved parsers methods and requires ordered * Added test for oauth response parsers * Fix namespace --------- Co-authored-by: Francisco Bolívar <francisco.bolivar@nazaries.com>
- Loading branch information
Showing
110 changed files
with
2,265 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
inherit_from: https://raw.githubusercontent.com/decidim/decidim/release/0.27-stable/.rubocop.yml | ||
|
||
RSpec/AnyInstance: | ||
Exclude: | ||
- 'spec/omni_auth/strategies/civicrm_spec.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Civicrm | ||
module Api | ||
module Base | ||
module V3 | ||
class BaseQuery < Base::BaseQuery | ||
attr_reader :result, :request | ||
|
||
protected | ||
|
||
def json_params(params) | ||
params.merge( | ||
sequential: 1 | ||
).to_json | ||
end | ||
|
||
def store_result | ||
return unless success? | ||
|
||
@result = parsed_response | ||
@result = @result.deep_symbolize_keys if @result.is_a? Hash | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Civicrm | ||
module Api | ||
module Base | ||
module V3 | ||
class FindQuery < BaseQuery | ||
protected | ||
|
||
def json_params(params) | ||
params.deep_merge( | ||
sequential: 1 | ||
).to_json | ||
end | ||
|
||
def parsed_response | ||
self.class.parse_item(response["values"].first) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Civicrm | ||
module Api | ||
module Base | ||
module V3 | ||
class ListQuery < BaseQuery | ||
protected | ||
|
||
def json_params(params) | ||
params.deep_merge( | ||
sequential: 1, | ||
options: { limit: 0 } | ||
).to_json | ||
end | ||
|
||
def parsed_response | ||
response["values"].map { |item| self.class.parse_item(item) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Civicrm | ||
module Api | ||
module Base | ||
module V3 | ||
class Request | ||
def initialize(verify_ssl: true) | ||
@verify_ssl = verify_ssl | ||
end | ||
|
||
attr_accessor :response | ||
|
||
def self.get(params, verify_ssl: true) | ||
instance = Request.new(verify_ssl: verify_ssl) | ||
response = instance.connection.get Decidim::Civicrm::Api.url do |request| | ||
request.params = instance.base_params.merge(params) | ||
# puts [request.path, URI.encode_www_form(request.params.sort)].join("/?") # DEBUG, to obtain the correct URL for stub_request | ||
end | ||
|
||
raise Decidim::Civicrm::Error, response.reason_phrase unless response.success? | ||
|
||
instance.response = JSON.parse(response.body).to_h | ||
instance | ||
end | ||
|
||
def self.post(params, verify_ssl: true) | ||
instance = Request.new(verify_ssl: verify_ssl) | ||
response = instance.connection.post Decidim::Civicrm::Api.url do |request| | ||
request.params = instance.base_params.merge(params) | ||
end | ||
|
||
raise Decidim::Civicrm::Error, response.reason_phrase unless response.success? | ||
|
||
instance.response = JSON.parse(response.body).to_h | ||
instance | ||
end | ||
|
||
def connection | ||
@connection ||= Faraday.new(ssl: { verify: @verify_ssl }) | ||
end | ||
|
||
def base_params | ||
Decidim::Civicrm::Api.credentials.merge( | ||
action: "Get" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Civicrm | ||
module Api | ||
module Base | ||
module V4 | ||
class BaseQuery < Base::BaseQuery | ||
attr_reader :result, :request | ||
|
||
def store_result | ||
return unless success? | ||
|
||
@result = parsed_response | ||
@result[:values] = @result[:values].deep_symbolize_keys if @result[:values].is_a? Hash | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.