Class: Ecfr::SubscriptionsService::Subscription

Inherits:
Base show all
Defined in:
lib/ecfr/subscriptions_service/subscription.rb

Constant Summary collapse

SUBSCRIPTIONS_PATH =
"v1/subscriptions"

Constants inherited from Base

Base::SUPPORTED_ARRAY_ACCESSORS

Instance Attribute Summary collapse

Attributes inherited from Base

#metadata, #request_data, #response_status, #results

Class Method Summary collapse

Methods inherited from Base

base_url, service_name, service_path

Methods inherited from Base

basic_auth_client_options, #each, #initialize, metadata, metadata_key, result_key

Methods included from Extensible

#inherited

Methods included from AttributeMethodDefinition

included, #initialize

Methods inherited from Client

build, cache_key, client, client_pool, delete, execute, get, handle_response, perform, post, purge

Methods included from ParallelClient

included

Constructor Details

This class inherits a constructor from Ecfr::Base

Instance Attribute Details

#created_atDate (readonly)

date the subscription was created

Returns:

  • (Date)


16
17
18
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 16

attribute :created_at,
type: :date,
desc: "date the subscription was created"

#delivery_countInteger (readonly)

the number of times the subscription has been delivered

Returns:

  • (Integer)


9
10
11
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 9

attribute :delivery_count,
type: :integer,
desc: "the number of times the subscription has been delivered"

#idInteger (readonly)

the subscription id

Returns:

  • (Integer)


12
13
14
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 12

attribute :id,
type: :integer,
desc: "the subscription id"

#last_delivered_atDate (readonly)

last date this subscription had matches and was delivered

Returns:

  • (Date)


19
20
21
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 19

attribute :last_delivered_at,
type: :date,
desc: "last date this subscription had matches and was delivered"

#parametersHash (readonly)

Returns with “query”, and “hierarchy” keys.

Returns:

  • (Hash)

    with “query”, and “hierarchy” keys



26
27
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 26

attribute :parameters,
desc: "the subscription search parameters"

#titleString (readonly)

a description of the subscription

Returns:

  • (String)


6
7
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 6

attribute :title,
desc: "a description of the subscription"

Class Method Details

.create_subscription(user_id, subscription_data) ⇒ <Subscription>

Create a subscription for a user

Parameters:

  • user_id (<Integer>)

    id of user

  • subscription_data (<Hash>)

    arguments required to create a subscription

Options Hash (subscription_data):

  • requesting_ip (String) — default: required
  • search (Hash) — default: required
  • search[:query] (String)

    subscription search terms

  • search[:hierarchy] (Ecfr::Common::Hierarchy)

    hierarchy to limit subscription search

Returns:



59
60
61
62
63
64
65
66
67
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 59

def self.create_subscription(user_id, subscription_data)
  perform(
    :post,
    "#{SUBSCRIPTIONS_PATH}/#{user_id}",
    params: subscription_data,
    client_options: basic_auth_client_options,
    perform_options: {attributes_key: "subscription"}
  )
end

.delete_subscription(user_id, token, subscription_id) ⇒ [<Subscription>, <Integer>]

Delete a subscription

Parameters:

  • user_id (<Integer>)

    id of user

  • token (<String>)

    unique delete token

  • subscription_id (<String>)

    id of subscription

Returns:

  • ([<Subscription>, <Integer>])

    the deleted subscription and response code



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 78

def self.delete_subscription(user_id, token, subscription_id)
  unsubscribe_data = {
    token: token,
    user_id: user_id,
    subscription_id: subscription_id
  }

  subscription = perform(
    :delete,
    "#{SUBSCRIPTIONS_PATH}/unsubscribe",
    params: unsubscribe_data,
    client_options: basic_auth_client_options,
    perform_options: {attributes_key: "subscription"}
  )

  [subscription, subscription.response_status]
end

.get_subscriptions(user_id) ⇒ [<Subscription>]

Retrive a list of subscriptions for a user

Parameters:

  • user_id (<Integer>)

    id of user

Returns:



38
39
40
41
42
43
44
# File 'lib/ecfr/subscriptions_service/subscription.rb', line 38

def self.get_subscriptions(user_id)
  perform(
    :get,
    "#{SUBSCRIPTIONS_PATH}/#{user_id}.json",
    client_options: basic_auth_client_options
  )
end