Git Product home page Git Product logo

baidu-sms's Introduction

Baidu Search Marketing Service

This gem is an easy-to-use, thin wrapper around the Baidu Search Marketing Service SOAP API v3.

This gem does not support the v4 JSON API or the BulkJobService.

Installation

gem install baidu-sms

Usage

Each service is initialized with a hash with three symbol keys:

credentials = {
  username: 'username',
  password: 'password',
  token: 'apitoken'
}

There are three implemented services: ReportService, AdgroupService, and KeywordService.

service = BaiduSMS::ReportService.new(credentials)
service = BaiduSMS::AdgroupService.new(credentials)
service = BaiduSMS::KeywordService.new(credentials)

Using the ReportService

When you create a report, you'll get an ID:

params = {
  performanceData: %w[cost cpc click impression ctr cpm conversion],
  startDate: Date.today - 1,
  endDate: Date.today - 1,
  levelOfDetails: BaiduSMS::LevelOfDetails::ACCOUNT
}

id = service.create_report(BaiduSMS::Reports::ACCOUNTS, params)

You can reference report type and level of detail by module constant or by name:

BaiduSMS::Reports.from_name('accounts')
# equals 
BaiduSMS::Reports::ACCOUNTS

# and

BaiduSMS::LevelOfDetails::ACCOUNT
# equals
BaiduSMS::LevelOfDetails.from_name('account')

You need to poll to discover if the report is ready yet:

if service.report_ready?(id)

Once the report is ready, you can get the URL where the report can be downloaded from:

service.report_url(id) if service.report_ready?(id)

You can download the report from this URL.

Using the other services

These services are synchronous; calling them will return results without having to poll. Look at the methods in these classes to see the return types and how to call them.

Tests

The services have tests - to run them, you need to create a file called credentials.yml at the root of the repository, with this format in YAML:

:username: username
:password: password
:token: apitoken

You can then run the tests by running rspec.

baidu-sms's People

Contributors

hypernova2002 avatar andytinycat avatar rhesketh avatar robertino avatar

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.