帮酷LOGO
  • 显示原文与译文双语对照的内容
A Ruby wrapper for the Desk.com V2 REST API

  • 源代码名称:desk
  • 源代码网址:http://www.github.com/chriswarren/desk
  • desk源代码文档
  • desk源代码下载
  • Git URL:
    git://www.github.com/chriswarren/desk.git
  • Git Clone代码到本地:
    git clone http://www.github.com/chriswarren/desk
  • Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/chriswarren/desk
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
  • 桌面 ruby-gem

    用于 Desk.com API的一个 ruby 包装器

    安装

    gem install desk

    1.0.0中新增的内容?

    完全重写为 Desk.com API v2

    对于从API升级的那些升级,请查看过渡指南 。

    帮助我正在获取: ! "recognize无法识别你的引擎规格。 请指定符号或者类。 ( RuntimeError )"

    你需要显式地需要一个JSON库。 我们推荐 yajl

    概述

    Desk.com's API v2遵循( 几乎)的标准结构,每个端点( 请参见示例的最后部分以了解不规则) 。 每个端点impliments部分或者全部执行以下操作: 列表,搜索,显示,创建,更新和删除。 此外,某些端点使用相同的操作列表的impliment子端点。

    端点操作和子终结点操作是按以下方式作为方法的implimented:

    [action]_[endpoint] or [action]_[endpoint]_[sub-endpoint]

    http://dev.desk.com/API/cases
    案例终结是一个很好的例子。 它 impliments,搜索,显示,创建和更新操作。 它还为与案例相关的消息。回复。注释和附件添加impliments子端点。 查看上链接以获得更多信息。

    对于事例终结点,创建操作的外观如下:

    Desk.create_case(args)

    对于下面的应答子终结点,更新操作将如下所示:

    Desk.update_case_reply(case_id, reply_id, args)

    注意,如 Desk.com API文档中所示,列表和搜索操作更改多个端点或者子端点。 例如:

    Desk.search_cases
    Desk.list_case_replies(case_id)

    别名

    为了便于使用,列表和显示端点和子端点方法具有除去操作的别名。 这些翻译如下:

    list_[endpoint plural] => [endpoint plural]
    show_[endpoint] => [endpoint]
    list_[endpoint]_[sub-endpoint pluaral] => [endpoint]_[sub-endpoint plural]
    show_[endpoint]_[sub-endpoint] => [endpoint]_[sub-endpoint]

    对于would终结点和应答子终结点,如下所示:

    Desk.cases
    Desk.case(case_id)
    Desk.case_replies(case_id)
    Desk.case_reply(case_id, reply_id)

    另外,对于impliment的端点,列表和列表别名将智能地使用正确的API操作来提供所提供的参数。 含义,以下所有内容均有效:

    Desk.cases
    Desk.cases(:page => 2)
    Desk.cases(:status =>"new,open")
    Desk.cases(:status =>"new,open", :page => 2, :per_page => 10)

    响应

    原始API响应可用( 请参见下面),结果默认情况下转换为更清晰更易于访问的ruby 对象,从而允许以下各项:

    cases = Desk.cases
    cases.each do |c|
     puts c.priority
     puts c.status
    end

    对于诸如显示,创建和更新端点字段,可以在对象 root 中访问端点字段,例如:

    c = Desk.case(case_id)
    puts c.priority
    puts c.status

    此外,API v2中的新"_links"也可以通过这种方式轻松访问。 因为每个链接( 像自我,先,下,等) 包含完全格式化的API回调,所以我们可以直接加载该链接的结果并返回结果对象。 这允许清洁,简单的代码,如下面的所有的培训案例:

    cases = Desk.list_cases
    while cases
     cases.each do |c|
     # do something with each case
     end
     cases = cases.next
    end

    或者轻松访问指定的案例用户和分配的组:

    c = Desk.show_case(case_id)
    user_object = c.assigned_user
    group_object = c.assigned_group

    原始响应

    虽然几乎所有的Desk.com API结果都可以访问,但是以某种形式,使用原始结果之上的简单对象键仍然可以通过"原始"键进行切换。 这允许:

    c = Desk.show_case(case_id)
    puts c.raw["_links"]["self"]["class"]

    用法示例

    require"rubygems"
    require"desk"
    # All methods require authentication. To get your Desk OAuth credentials,
    # register an app in the Desk.com admin for your account at http://your-domain.desk.com/admin
    Desk.configure do |config|
     config.support_email ="help@example.com"
     config.subdomain = YOUR_DESK_SUBDOMAIN
     config.consumer_key = YOUR_CONSUMER_KEY
     config.consumer_secret = YOUR_CONSUMER_SECRET
     config.oauth_token = YOUR_OAUTH_TOKEN
     config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
    end
    ######
    # List examples
    ######
    # List cases
    Desk.cases
    # List customers
    Desk.customers
    # List site settings
    Desk.site_settings
    # List twitter users
    Desk.twitter_users
    # List article translations
    Desk.article_translations(1)
    # List case notes
    Desk.case_notes(12345)
    ######
    # Search examples
    ######
    # Search articles
    Desk.articles(:text =>"happy", :topic_ids =>"1,2,4")
    # Search cases
    Desk.cases(:since_id => 12345)
    # Search companies
    Desk.companies(:q =>"acme")
    # Search customers
    Desk.customers(:last_name =>"Smith", :custom_field =>"IS 5416")
    ######
    # Show examples
    ######
    # Get a specific custom field
    Desk.custom_field(1)
    # Get a specific facebook user
    Desk.facebook_user(1234)
    # Get a specific case
    Desk.case(12345)
    # Get a specific twitter account
    Desk.twitter_account(2)
    ######
    # Create examples
    ######
    # Create a new phone case
    Desk.create_case(
     :type =>"phone",
     :subject =>"Creating a case via the API",
     :priority => 4,
     :status =>"open",
     :labels => ["Spam","Ignore" ],
     :_links => {
     :customer => {
     :href =>"/api/v2/customers/1",
     :class =>"customer"
     },
     :assigned_user => {
     :href =>"/api/v2/users/1",
     :class =>"user"
     },
     :assigned_group => {
     :href =>"/api/v2/groups/1",
     :class =>"group"
     },
     :locked_by => {
     :href =>"/api/v2/users/1",
     :class =>"user"
     },
     :entered_by => {
     :href =>"/api/v2/users/1",
     :class =>"user"
     }
     },
     :message => {
     :direction =>"out",
     :body =>"Please assist me with this case",
     }
    )
    # Create a new label
    Desk.create_label(
     :name =>"MyLabel",
     :description =>"A Test Label",
     :types => ["case","macro" ],
     :color =>"blue"
    )
    # Create a new topic
    Desk.create_topic(
     :name =>"Social Media",
     :allow_questions => true,
     :in_support_center => true
    )
    ######
    # Update examples
    ######
    # Update a customer
    Desk.update_customer(123,
     :first_name =>"Johnny",
     :emails => [
     { :type =>"work", :value =>"johnny@acme.com" },
     { :type =>"other", :value =>"johnny@other.com" }
     ],
     :custom_fields => { :level =>"super" }
    )
    # Update an integration URL
    Desk.update_integration_url(10, :enabled => false)
    # Update a macro
    Desk.update_macro(5, :name =>"Macro 5")
    ######
    # Delete examples
    ######
    # Delete a case
    Desk.delete_case(12345)
    # Delete a label
    Desk.delete_label(2)
    # Delete a macro
    Desk.delete_macro(10)
    ######
    # Sub-endpoint examples
    ######
    # Get the original message for a specific case
    Desk.case_message(12345)
    # Get the cases for a specifc filter
    Desk.filter_cases(8)
    # Output all replies for a specific case
    Desk.case_replies(12345).each { |r| puts r.body }
    # Update the translation for a specific topic
    Desk.update_topic_translation(1,"ja", :name =>"The Japanese Translation")
    # Delete a specifc attachment for a specific case
    Desk.delete_case_attachment(12345, 10)
    ######
    # _link helper examples
    ######
    # Output the original message and all replies using the _link helpers
    c = Desk.case(12345)
    puts c.message.body
    c.replies.each { |r| puts r.body }
    # Output all article subjects, who created them and who last updated them
    Desk.articles.each do |a|
     puts a.subject
     puts"Created at: #{a.created_at} by #{a.created_by.public_name}"
     puts"Updated at: #{a.updated_at} by #{a.updated_by.public_name}"
    end
    # For all customers who have been created since 01/01/2013, output the
    # original message for all cases for those customers
    Desk.customers(:since_created_at => 1385856000).each do |customer|
     customer.cases.each do |c|
     puts c.message.body
     end
    end
    ######
    # Helper methods
    ######
    # Add an address, email and phone
    # number to an existing customer
    customer = Desk.customer(12345)
    customer_add_address(customer,"12545 Riata Vista Cir, Austin, TX 78727","work")
    customer_add_email(customer,"ruby@desk.com")
    customer_add_phone_number(customer,"123-456-7890","other")
    # Delete a specific address, email and
    # phone number from an existing customer
    customer = Desk.customer(12345)
    customer_delete_address(customer,"12545 Riata Vista Cir, Austin, TX 78727")
    customer_delete_email(customer,"ruby@desk.com")
    customer_delete_phone_number(customer,"123-456-7890")
    # Delete all addresses and phone
    # numbers of a specific type
    customer = Desk.customer(12345)
    customer_delete_address(customer,"work")
    customer_delete_phone_number(customer,"other")
    # The delete helpers also support mixing
    # and matching multiple items
    customer = Desk.customer(12345)
    customer_delete_address(customer,"work","other",""12545 Riata Vista Cir, Austin, TX 78727")
    customer_delete_email(customer,"ruby@desk.com","gem@desk.com")
    customer_delete_phone_number(customer,"work","123-456-7890","908-456-321")
    ######
    #"non-standard" examples
    ######
    # Get a case url
    Desk.case_url(12345)
    # Get the history for a sepcific case
    Desk.case_history(12345)
    # Show insights meta data
    Desk.insights_meta
    # Create insights report
    Desk.create_insights_report(
     :resolution =>"days",
     :min_date =>"2013-12-01",
     :max_date =>"2013-12-16",
     :dimension1_name =>"*",
     :dimension1_values =>"*",
     :dimension2_name =>"*",
     :dimension2_values =>"*"
    )
    # Show the daily system message
    Desk.system_message
    # Basic authentication with username and password; not recommended
    Desk.configure do |config|
     config.support_email ="help@example.com"
     config.subdomain = YOUR_DESK_SUBDOMAIN
     config.consumer_key = YOUR_CONSUMER_KEY
     config.consumer_secret = YOUR_CONSUMER_SECRET
     config.auth_method = Desk::Authentication::Methods:BASIC
     config.basic_auth_username = YOUR_USERNAME
     config.basic_auth_password = YOUR_PASSWORD
    end

    本着免费软件的精神,鼓励帮助改进这个项目。

    以下是你可以提供的一些方式:

    • 通过使用 alpha,测试版和预发布版本
    • 通过报告 Bug
    • 通过建议新功能
    • 通过编写或者编辑文档
    • 通过编写规范
    • 通过编写代码( 没有补丁的patch太小: 修正错误,添加注释,清除不一致的空白
    • 通过重构代码
    • 通过关闭问题
    • 通过检查修补程序

    所有贡献者将被添加到历史文件中,并获得社区的尊重和感谢。

    提交问题

    我们使用 GitHub问题跟踪程序跟踪和功能。 提交 Bug 报告或者功能请求之前,请检查它是否还没有提交。 你可以通过投票来指示对现有issuse的支持。 当提交 Bug 报告时,请包括包含堆栈跟踪( 包括版本。ruby 版本和操作系统)的堆栈跟踪和任何详细信息。 理想情况下,Bug 报告应该包含一个请求失败的请求请求。

    提交请求请求

    • fork 项目。
    • 创建主题分支。
    • 实现你的功能或者 Bug 修复。
    • 为你的功能或者 Bug 修复添加文档。
    • 运行包 exec rake doc:yard 。 如果你的更改不是 100%文档,请返回到步骤 4.
    • 为你的功能或者 Bug 修复添加规范。
    • 运行包 exec rake规范。 如果你的更改未覆盖 100%,请返回到步骤 6.
    • 提交并推动更改。
    • 提交请求请求。请不要包括对 gemspec,版本或者历史文件的更改。 ( 如果你想出于某种原因创建自己的版本,请在单独的提交中进行。)

    版权

    版权所有( c ) 2012 Chris warren/Zencoder 有关详细信息,请参阅许可证。




    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语