GithubHelp home page GithubHelp logo

mhenrixon / active_campaign Goto Github PK

View Code? Open in Web Editor NEW
42.0 7.0 74.0 553 KB

A simple ruby wrapper for the ActiveCampaign API

Home Page: http://www.activecampaign.com/api/

License: MIT License

Ruby 99.58% Shell 0.42%

active_campaign's Introduction

Build StatusCode ClimateTest Coverage FOSSA Status

Active::Campaign::Ruby

A simple wrapper for the ActiveCampaign API. Since their API seems to be basically just form posts to their server don't complain here about the way it works. The only thing we really changed was how results are wrapped and returned and you can read more about that here.

Installation

Add this line to your application's Gemfile:

gem 'active_campaign'

And then execute:

bundle

Or install it yourself as:

gem install active_campaign

Usage

# To setup the client
client = ::ActiveCampaign::Client.new(
        api_url: 'YOUR-ENDPOINT', # e.g. 'https://youraccount.api-us1.com/api/3'
        api_token: 'YOUR-API-KEY') # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'

# or configure globally for all clients
::ActiveCampaign.configure do |config|
  config.api_url = 'YOUR-ENDPOINT' # e.g. 'https://youraccount.api-us1.com/api/3'
  config.api_token = 'YOUR-API-KEY' # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'
end
# To create a contact
ActiveCampaign.create_contact(
  email: "[email protected]", 
  first_name: "Mika",
  last_name: "El",
  phone: "bogusnumber",
)
# To sync a contact (create if doesn't exist or update if matching email)
ActiveCampaign.sync_contact(
  email: "[email protected]", 
  first_name: "Mika",
  last_name: "El",
  phone: "bogusnumber",
)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Rebase against master we want 1 commit per feature please
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

FOSSA Status

active_campaign's People

Contributors

anilrh avatar dakariakin avatar drakula2k avatar ekyfauzi avatar jeffreybiles avatar jmlacroix avatar kartikupadhyay90 avatar kenzhengguan avatar maysam avatar mcmire avatar mhenrixon avatar rylwin avatar seang7 avatar tdtadeu avatar timchaston avatar toreym avatar yihyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

active_campaign's Issues

"Undefined method `dependency`" when requiring the gem

After installing the gem locally from the master branch, when I try to require 'active_campaign' in an irb session I get the following error:

.../gems/active_campaign-3.0.0/lib/active_campaign/faraday/middleware/request.rb:12:in `<class:Request>':
undefined method `dependency' for ActiveCampaign::Faraday::Middleware::Request:Class (NoMethodError)

This is because I have a version of Faraday greater than 2.0 installed and the dependency method has been deprecated. (source).

To fix this I changed the gemspec to use Faraday 1 instead, which fixed the problem:

-  spec.add_dependency 'faraday',        '>= 1.0', '< 3.0'
+  spec.add_dependency 'faraday',        '>= 1.0', '< 2.0'

Could we upgrade the master branch to Faraday 2? I'm willing to submit a PR.

Bundle Not Installing Latest Version

When I try to add the gem 'active_campaign' to my gemfile and bundle, version 0.1.16 gets installed rather than the latest version and doesn't match up with the documentation in the readme as a result. I as able to get around it at the moment by directly referencing the repo, but wanted to make sure you and others were aware this was happening.

Can't get API to work at all

I'm having all sorts of issues with the API and can't tell if it's just me or if the documentation is out of date.

First, I'm unable to connect with:

client = ::ActiveCampaign::Client.new(
        api_url: 'YOUR-ENDPOINT', # e.g. 'https://youraccount.api-us1.com/api/3'
        api_token: 'YOUR-API-KEY')

I have to use api_endpoint and api_key instead of api_url and api_token and it doesn't work at all with the /api/3 endpoint. I have to point it at /admin/api.php. This isn't documented anywhere. I had to parse it together from support requests and a lot of hacking.

Once I'm actually connected to the API, I can hardly make any calls. For example, I've tried every possible variation I can think of to retrieve all lists:
client.lists, client.get_lists, client.list.

They all generate a version of:

client.show_lists => 
NoMethodError: undefined method `show_lists' for #<ActiveCampaign::Client:0x00007fbaede2b6c0>

The only thing that generates a response is client.list_list which gives me the following:

=> {"result_code"=>0,
 "result_message"=>"Failed: Nothing is returned",
 "result_output"=>"json",
 "results"=>[]}

Any plans on releasing a new version?

Hi there is there any plan on releasing a newer version of the gem?

Master has diverged quite far apart from the last release version, refer to: v0.1.13...master

And also there's a few issue such as #20
which have caused the gem to not functioning (which has already been fixed).

I have forked my own version in order to access the lastest version however I would like to know when's the next release so that I can point the gem references back.

Thanks.

Upgrading to 3.0

I opened this issue so we can debate it here. I accidentally started the discussion at #33, but I didn't want to go on there since that issue asks for something different, yet related.

V3 is RESTful, at last! https://developers.activecampaign.com/reference

@mhenrixon Should we maintain the same structure of method call using method_missing in the main module, or could I suggest we create resource classes to map their new API?

undefined method `each_with_object' for "400":String

When running ActiveCampaign.show_contact(403) returns the following error:

Traceback (most recent call last):
        2: from (irb):4
        1: from (irb):4:in `rescue in irb_binding'
NoMethodError (undefined method `each_with_object' for "400":String)

Investigating it, I discovered that it happens only when the user is in a list, because of this method:

    # active_campaign/lib/active_campaign/transform_hash.rb:48
    def transform_value(value, *new_case)
      case value
      when Hash
        transform_keys(value, *new_case)
      when Array
        value.map { |item| transform_key(item, *new_case) }
      else
        value
      end
    end

This specific user has a contactsList field returned as:

        "contactLists": [
            "400"
        ],

Then, when trying to deal with a string as an object, it returns that error.

configure?

how do you have this setup to configure? I saw another issue and pull request related to this, but it doesn't take advantage of the client singleton object you have setup. Any guidance on how you intended to configure the API? Thanks!

Using `Client` directly breaks following README examples

Hey there! I'm just starting down the path of an ActiveCampaign integration working against HEAD where I'm using ActiveCampaign:::Client.new and found I needed to add a couple extra options vs. what's shown in the README (which suggests I only need to set api_url and api_token).

    ActiveCampaign::Client.new(
      api_url: api_url,
      api_token: api_token,
      response_middleware: {},
      adapter: :net_http,
    )

If I don't set response_middlewhere to empty hash, I get a nil error when invoking #none? on nil. And if I don't specify an adapter, faraday can't make requests (error is "wrong constant name").

Would you be open to a PR that either:

  • updates the README to show these other keys?
  • sets a default adapter value / gracefully handles a nil response_middleware value?

Which of these approaches would be preferred? Let me know and I'd be happy to open a PR.

Thanks!

contact_sync method raising SSL error

Im getting the following error while trying to sync contacts. It previously worked fine and suddenly started to see this error:

Excon::Error::Socket - SSL_connect returned=1 errno=0 state=SSLv3/TLS write client hello: tlsv1 alert protocol version (OpenSSL::SSL::SSLError)

undefined method for ActiveCampaign:Module

I just can't get this gem to work. I've followed the setup instructions but when I try ActiveCampaign.list_list ids: 'all' I just get undefined method 'list_list' for ActiveCampaign:Module. I've looked at the module's source code and see that method_missing is meant to create the client object and invoke the method on it, but that doesn't seem to be happening.

I'm using active_campaign version 0.1.13 and Ruby 2.2.1. Thanks.

Error when using contact_add (but likely other endpoints too)

When using the contact_add endpoint, even if I supply valid information as follows:

active_campaign_client = ActiveCampaign::Client.new
active_campaign_client.contact_add(
  "first_name" => "John",
  "email" => "[email protected]",
  "p[999]" => 999,
)

then I get this response from the API:

{"result_code"=>0, "result_message"=>"Contact Email Address is not valid.", "result_output"=>"json", "results"=>[]}

I believe this is happening because the API expects this header to be present:

Content-Type: application/x-www-form-urlencoded

and it is not.

Getting "You are not authorized to access this file" error when calling list_list

I'm running into this complete error:

{"result_code"=>0, "result_message"=>"You are not authorized to access this file", "result_output"=>"json", "results"=>[]}

When calling the client.list_list ids: 'all' after building the client like this:

client = ::ActiveCampaign::Client.new(
     api_endpoint: 'https://MY_URL.api-us1.com/admin/api.php',        
     api_key: 'MY_KEY_HERE'
) 

This code actually used to work properly but seems to have broken. Is anyone else seeing this issue? Or have any tips?

JSON::ParserError: A JSON text must at least contain two octets!

I using active_campaign version 0.1.14 and i have issue

@client = ::ActiveCampaign::Client.new(api_endpoint: ENV['ACTIVE_CAMPAIGN_ENDPOINT'], api_key: ENV['ACTIVE_CAMPAIGN_KEY'])
   params = {
        :query => { :listid => 1 },
        :id => 1,
        :email=>'[email protected]',
        :ip4 => '127.0.0.1'
      }
@client.contact_add(params)

Error log:

JSON::ParserError: A JSON text must at least contain two octets!
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/json_pure-1.8.3/lib/json/common.rb:155:in `initialize'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/json_pure-1.8.3/lib/json/common.rb:155:in `new'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/json_pure-1.8.3/lib/json/common.rb:155:in `parse'
    from /Users/julian/.rvm/gems/ruby-2.3.0@skilltracker/gems/active_campaign-0.1.14/lib/active_campaign/client.rb:77:in `request'
    from /Users/julian/.rvm/gems/ruby-2.3.0@skilltracker/gems/active_campaign-0.1.14/lib/active_campaign/client.rb:51:in `get'
    from /Users/julian/.rvm/gems/ruby-2.3.0@skilltracker/gems/active_campaign-0.1.14/lib/active_campaign/method_creator.rb:28:in `block in define_api_method'
    from /Users/julian/Documents/vinova/skilltracker-backend/app/services/service/active_campaign.rb:17:in `contact_add'
    from (irb):14
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
... 2 levels...
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `block in load'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/commands/rails.rb:6:in `call'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/command_wrapper.rb:38:in `call'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/application.rb:191:in `block in serve'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/application.rb:161:in `fork'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/application.rb:161:in `serve'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/application.rb:131:in `block in run'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/application.rb:125:in `loop'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/application.rb:125:in `run'
    from /Users/julian/.rvm/gems/ruby-2.3.0@global/gems/spring-1.7.1/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/julian/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/julian/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'

JSON Error

Hi, after gem install, i try connect with method:

client = ::ActiveCampaign::Client.new(
      api_url: cuenta.api_url, # e.g. 'https://youraccount.api-us1.com/api/3'
      api_token: cuenta.api_token) # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'

and if i want to get list, fail ๐Ÿ‘Ž

2.5.1 :002 > client.list_list
D, [2020-09-07T18:18:33.896037 #21082] DEBUG -- : HTTPI TLSv1_2/none GET request to subdomain.activehosted.com (net_http)
Traceback (most recent call last):
1: from (irb):2
JSON::ParserError (783: unexpected token at '

)

    <div style="font-size:15px; color:#333; padding: 50px; font-family:Arial, Helvetica, sans-serif;">
    <div style="font-size:33px; padding:12px;">Not Found</div>
    <div>Sorry, this page could not be found.<br />

Please check your link/URL and try again.


'

please help me

Error when run server (ActiveCampaign::VERSION)

Hi,

When I add active_campaign gem into my Gemfile and run bundle install then rails s, I get error like this:

/Users/ekyfauzi/.rvm/gems/ruby-2.1.2/gems/active_campaign-0.1.10/lib/active_campaign/configuration.rb:6:in `<module:Configuration>': uninitialized constant ActiveCampaign::VERSION (NameError)

anyone can help me, please?

Thanks,

Authentication

Thanks for creating this wrapper (the "API" is a nightmare).

I'm trying to figure out how to authenticate, but didn't find anything in the README that explains it. Would I just need to include the API key in the contact_sync call I'm making?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.