{"action":"created","comment":{"url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/comments/60763675","id":60763675,"diff_hunk":"@@ -10,4 +10,7 @@ group :development do\n   gem 'rubysl',                    :platforms => :rbx\n   gem 'rubysl-resolv', '~> 2.0',   :platforms => :rbx\n   gem 'racc',                      :platforms => :rbx\n+\n+  gem 'webmock', '~> 1.7'\n+  gem 'pry'","path":"Gemfile","position":6,"original_position":6,"commit_id":"cee7cf87fac88e7b2a8aa4a0ce57062ac020419e","original_commit_id":"cee7cf87fac88e7b2a8aa4a0ce57062ac020419e","user":{"login":"bhelx","id":185919,"avatar_url":"https://avatars.githubusercontent.com/u/185919?v=3","gravatar_id":"","url":"https://api.github.com/users/bhelx","html_url":"https://github.com/bhelx","followers_url":"https://api.github.com/users/bhelx/followers","following_url":"https://api.github.com/users/bhelx/following{/other_user}","gists_url":"https://api.github.com/users/bhelx/gists{/gist_id}","starred_url":"https://api.github.com/users/bhelx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhelx/subscriptions","organizations_url":"https://api.github.com/users/bhelx/orgs","repos_url":"https://api.github.com/users/bhelx/repos","events_url":"https://api.github.com/users/bhelx/events{/privacy}","received_events_url":"https://api.github.com/users/bhelx/received_events","type":"User","site_admin":false},"body":"I'm going to do a follow up PR to remove the gemfile and put stuff in the gemspec","created_at":"2016-04-22T16:08:17Z","updated_at":"2016-04-22T16:08:17Z","html_url":"https://github.com/recurly/recurly-client-ruby/pull/237#discussion_r60763675","pull_request_url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237","_links":{"self":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/comments/60763675"},"html":{"href":"https://github.com/recurly/recurly-client-ruby/pull/237#discussion_r60763675"},"pull_request":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237"}}},"pull_request":{"url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237","id":67220139,"html_url":"https://github.com/recurly/recurly-client-ruby/pull/237","diff_url":"https://github.com/recurly/recurly-client-ruby/pull/237.diff","patch_url":"https://github.com/recurly/recurly-client-ruby/pull/237.patch","issue_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/237","number":237,"state":"open","locked":false,"title":"Usage Based Billing","user":{"login":"bhelx","id":185919,"avatar_url":"https://avatars.githubusercontent.com/u/185919?v=3","gravatar_id":"","url":"https://api.github.com/users/bhelx","html_url":"https://github.com/bhelx","followers_url":"https://api.github.com/users/bhelx/followers","following_url":"https://api.github.com/users/bhelx/following{/other_user}","gists_url":"https://api.github.com/users/bhelx/gists{/gist_id}","starred_url":"https://api.github.com/users/bhelx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhelx/subscriptions","organizations_url":"https://api.github.com/users/bhelx/orgs","repos_url":"https://api.github.com/users/bhelx/repos","events_url":"https://api.github.com/users/bhelx/events{/privacy}","received_events_url":"https://api.github.com/users/bhelx/received_events","type":"User","site_admin":false},"body":"This feature that is not yet enabled on all sites.\r\n\r\nThis introduces some new resources and updates to current resources to\r\nsupport the usage based billing (metered billing) feature.\r\n\r\nhttps://docs.recurly.com/docs/metered-billing\r\n\r\n### Using\r\n\r\n```ruby\r\nrequire 'date'\r\nrequire 'securerandom'\r\n\r\n# Let's create a new plan\r\nplan_code = SecureRandom.uuid\r\nplan = Recurly::Plan.create!(\r\n  plan_code: plan_code,\r\n  name: 'My Plan',\r\n  unit_amount_in_cents: { 'USD' => 10_00, 'EUR' => 8_00 },\r\n  setup_fee_in_cents: { 'USD' => 60_00, 'EUR' => 45_00 },\r\n  plan_interval_length: 1,\r\n  plan_interval_unit: 'months',\r\n  tax_exempt: false\r\n)\r\n\r\n# Create the plan add_on\r\nadd_on = plan.add_ons.create!(\r\n  add_on_code: 'marketing_emails',\r\n  name: 'Marketing Emails',\r\n  unit_amount_in_cents: 5,\r\n  add_on_type: :usage,\r\n  optional: true,\r\n  usage_type: :price,\r\n  measured_unit_id: 18783, # You need to create this measured unit in the dashboard\r\n)\r\n\r\n# This should be an account with a good billing info\r\naccount = Recurly::Account.find 'usageaccount'\r\n\r\n# Create the subscription add on\r\nsub_add_on = Recurly::SubscriptionAddOn.new('marketing_emails')\r\nsub_add_on.quantity = 1\r\n\r\n# create the subscription with the addon\r\nsubscription = Recurly::Subscription.create!(\r\n  plan_code: plan_code,\r\n  subscription_add_ons: [sub_add_on],\r\n  account: {\r\n    account_code: account.account_code\r\n  }\r\n)\r\n\r\n# we have this variable already, but finding it for demonstration purposes\r\nsub_add_on = subscription.subscription_add_ons.detect do |add_on|\r\n  add_on.add_on_code == 'marketing_emails'\r\nend\r\n\r\nsleep 1\r\n\r\nusage1 = sub_add_on.usage.build(\r\n  amount: 100,\r\n  merchant_tag: \"Batch of 100 marketing emails sent by customer\",\r\n  recording_timestamp: DateTime.now,\r\n  usage_timestamp: DateTime.now\r\n)\r\n\r\nusage1.save!\r\n\r\nusage2 = sub_add_on.usage.build\r\n\r\nusage2.amount = 50\r\nusage2.merchant_tag = \"Batch of 50 marketing emails sent by customer\"\r\nusage2.recording_timestamp = DateTime.now\r\nusage2.usage_timestamp = DateTime.now\r\n\r\nusage2.save!\r\n\r\n# You can create instead of build\r\nusage3 = sub_add_on.usage.create!(\r\n  amount: 200,\r\n  merchant_tag: \"Batch of 200 marketing emails sent by customer\",\r\n  recording_timestamp: DateTime.now,\r\n  usage_timestamp: DateTime.now\r\n)\r\n\r\n# Our usage search options\r\nsearch_options = {\r\n  billing_status: :all,   # (:all || :unbilled || :billed)\r\n  datetime_type: :usage,  # (:usage || :recording)\r\n#  start_datetime: NOW,    # greater than or equal to this date\r\n#  end_datetime: NOW,      # less than this date\r\n}\r\n\r\n# create the pager\r\n# takes per_page and stuff\r\n# see Pager class\r\npager = sub_add_on.usage.paginate(search_options)\r\n\r\n# iterate through our 3 usages\r\npager.find_each do |usage|\r\n  puts usage.inspect\r\nend\r\n```","created_at":"2016-04-20T16:42:22Z","updated_at":"2016-04-22T16:08:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9594261c396ae7c29c288642cc63e76aefb16ef3","assignee":{"login":"csmb","id":585697,"avatar_url":"https://avatars.githubusercontent.com/u/585697?v=3","gravatar_id":"","url":"https://api.github.com/users/csmb","html_url":"https://github.com/csmb","followers_url":"https://api.github.com/users/csmb/followers","following_url":"https://api.github.com/users/csmb/following{/other_user}","gists_url":"https://api.github.com/users/csmb/gists{/gist_id}","starred_url":"https://api.github.com/users/csmb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csmb/subscriptions","organizations_url":"https://api.github.com/users/csmb/orgs","repos_url":"https://api.github.com/users/csmb/repos","events_url":"https://api.github.com/users/csmb/events{/privacy}","received_events_url":"https://api.github.com/users/csmb/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237/commits","review_comments_url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237/comments","review_comment_url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/237/comments","statuses_url":"https://api.github.com/repos/recurly/recurly-client-ruby/statuses/cee7cf87fac88e7b2a8aa4a0ce57062ac020419e","head":{"label":"recurly:usage_based_billing","ref":"usage_based_billing","sha":"cee7cf87fac88e7b2a8aa4a0ce57062ac020419e","user":{"login":"recurly","id":144605,"avatar_url":"https://avatars.githubusercontent.com/u/144605?v=3","gravatar_id":"","url":"https://api.github.com/users/recurly","html_url":"https://github.com/recurly","followers_url":"https://api.github.com/users/recurly/followers","following_url":"https://api.github.com/users/recurly/following{/other_user}","gists_url":"https://api.github.com/users/recurly/gists{/gist_id}","starred_url":"https://api.github.com/users/recurly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/recurly/subscriptions","organizations_url":"https://api.github.com/users/recurly/orgs","repos_url":"https://api.github.com/users/recurly/repos","events_url":"https://api.github.com/users/recurly/events{/privacy}","received_events_url":"https://api.github.com/users/recurly/received_events","type":"Organization","site_admin":false},"repo":{"id":381812,"name":"recurly-client-ruby","full_name":"recurly/recurly-client-ruby","owner":{"login":"recurly","id":144605,"avatar_url":"https://avatars.githubusercontent.com/u/144605?v=3","gravatar_id":"","url":"https://api.github.com/users/recurly","html_url":"https://github.com/recurly","followers_url":"https://api.github.com/users/recurly/followers","following_url":"https://api.github.com/users/recurly/following{/other_user}","gists_url":"https://api.github.com/users/recurly/gists{/gist_id}","starred_url":"https://api.github.com/users/recurly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/recurly/subscriptions","organizations_url":"https://api.github.com/users/recurly/orgs","repos_url":"https://api.github.com/users/recurly/repos","events_url":"https://api.github.com/users/recurly/events{/privacy}","received_events_url":"https://api.github.com/users/recurly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/recurly/recurly-client-ruby","description":"A Ruby API wrapper for Recurly. Super Simple Subscription billing.","fork":false,"url":"https://api.github.com/repos/recurly/recurly-client-ruby","forks_url":"https://api.github.com/repos/recurly/recurly-client-ruby/forks","keys_url":"https://api.github.com/repos/recurly/recurly-client-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/recurly/recurly-client-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/recurly/recurly-client-ruby/teams","hooks_url":"https://api.github.com/repos/recurly/recurly-client-ruby/hooks","issue_events_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/recurly/recurly-client-ruby/events","assignees_url":"https://api.github.com/repos/recurly/recurly-client-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/recurly/recurly-client-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/recurly/recurly-client-ruby/tags","blobs_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/recurly/recurly-client-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/recurly/recurly-client-ruby/languages","stargazers_url":"https://api.github.com/repos/recurly/recurly-client-ruby/stargazers","contributors_url":"https://api.github.com/repos/recurly/recurly-client-ruby/contributors","subscribers_url":"https://api.github.com/repos/recurly/recurly-client-ruby/subscribers","subscription_url":"https://api.github.com/repos/recurly/recurly-client-ruby/subscription","commits_url":"https://api.github.com/repos/recurly/recurly-client-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/recurly/recurly-client-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/recurly/recurly-client-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/recurly/recurly-client-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/recurly/recurly-client-ruby/merges","archive_url":"https://api.github.com/repos/recurly/recurly-client-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/recurly/recurly-client-ruby/downloads","issues_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/recurly/recurly-client-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/recurly/recurly-client-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/recurly/recurly-client-ruby/labels{/name}","releases_url":"https://api.github.com/repos/recurly/recurly-client-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/recurly/recurly-client-ruby/deployments","created_at":"2009-11-22T19:32:14Z","updated_at":"2016-02-29T18:02:23Z","pushed_at":"2016-04-20T22:41:44Z","git_url":"git://github.com/recurly/recurly-client-ruby.git","ssh_url":"git@github.com:recurly/recurly-client-ruby.git","clone_url":"https://github.com/recurly/recurly-client-ruby.git","svn_url":"https://github.com/recurly/recurly-client-ruby","homepage":"http://recurly.com","size":989,"stargazers_count":135,"watchers_count":135,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":89,"mirror_url":null,"open_issues_count":12,"forks":89,"open_issues":12,"watchers":135,"default_branch":"master"}},"base":{"label":"recurly:master","ref":"master","sha":"0303c6f80551f8ec6d91ee306b616f78d4c0686e","user":{"login":"recurly","id":144605,"avatar_url":"https://avatars.githubusercontent.com/u/144605?v=3","gravatar_id":"","url":"https://api.github.com/users/recurly","html_url":"https://github.com/recurly","followers_url":"https://api.github.com/users/recurly/followers","following_url":"https://api.github.com/users/recurly/following{/other_user}","gists_url":"https://api.github.com/users/recurly/gists{/gist_id}","starred_url":"https://api.github.com/users/recurly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/recurly/subscriptions","organizations_url":"https://api.github.com/users/recurly/orgs","repos_url":"https://api.github.com/users/recurly/repos","events_url":"https://api.github.com/users/recurly/events{/privacy}","received_events_url":"https://api.github.com/users/recurly/received_events","type":"Organization","site_admin":false},"repo":{"id":381812,"name":"recurly-client-ruby","full_name":"recurly/recurly-client-ruby","owner":{"login":"recurly","id":144605,"avatar_url":"https://avatars.githubusercontent.com/u/144605?v=3","gravatar_id":"","url":"https://api.github.com/users/recurly","html_url":"https://github.com/recurly","followers_url":"https://api.github.com/users/recurly/followers","following_url":"https://api.github.com/users/recurly/following{/other_user}","gists_url":"https://api.github.com/users/recurly/gists{/gist_id}","starred_url":"https://api.github.com/users/recurly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/recurly/subscriptions","organizations_url":"https://api.github.com/users/recurly/orgs","repos_url":"https://api.github.com/users/recurly/repos","events_url":"https://api.github.com/users/recurly/events{/privacy}","received_events_url":"https://api.github.com/users/recurly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/recurly/recurly-client-ruby","description":"A Ruby API wrapper for Recurly. Super Simple Subscription billing.","fork":false,"url":"https://api.github.com/repos/recurly/recurly-client-ruby","forks_url":"https://api.github.com/repos/recurly/recurly-client-ruby/forks","keys_url":"https://api.github.com/repos/recurly/recurly-client-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/recurly/recurly-client-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/recurly/recurly-client-ruby/teams","hooks_url":"https://api.github.com/repos/recurly/recurly-client-ruby/hooks","issue_events_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/recurly/recurly-client-ruby/events","assignees_url":"https://api.github.com/repos/recurly/recurly-client-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/recurly/recurly-client-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/recurly/recurly-client-ruby/tags","blobs_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/recurly/recurly-client-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/recurly/recurly-client-ruby/languages","stargazers_url":"https://api.github.com/repos/recurly/recurly-client-ruby/stargazers","contributors_url":"https://api.github.com/repos/recurly/recurly-client-ruby/contributors","subscribers_url":"https://api.github.com/repos/recurly/recurly-client-ruby/subscribers","subscription_url":"https://api.github.com/repos/recurly/recurly-client-ruby/subscription","commits_url":"https://api.github.com/repos/recurly/recurly-client-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/recurly/recurly-client-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/recurly/recurly-client-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/recurly/recurly-client-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/recurly/recurly-client-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/recurly/recurly-client-ruby/merges","archive_url":"https://api.github.com/repos/recurly/recurly-client-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/recurly/recurly-client-ruby/downloads","issues_url":"https://api.github.com/repos/recurly/recurly-client-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/recurly/recurly-client-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/recurly/recurly-client-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/recurly/recurly-client-ruby/labels{/name}","releases_url":"https://api.github.com/repos/recurly/recurly-client-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/recurly/recurly-client-ruby/deployments","created_at":"2009-11-22T19:32:14Z","updated_at":"2016-02-29T18:02:23Z","pushed_at":"2016-04-20T22:41:44Z","git_url":"git://github.com/recurly/recurly-client-ruby.git","ssh_url":"git@github.com:recurly/recurly-client-ruby.git","clone_url":"https://github.com/recurly/recurly-client-ruby.git","svn_url":"https://github.com/recurly/recurly-client-ruby","homepage":"http://recurly.com","size":989,"stargazers_count":135,"watchers_count":135,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":89,"mirror_url":null,"open_issues_count":12,"forks":89,"open_issues":12,"watchers":135,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237"},"html":{"href":"https://github.com/recurly/recurly-client-ruby/pull/237"},"issue":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/237"},"comments":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/issues/237/comments"},"review_comments":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237/comments"},"review_comment":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/pulls/237/commits"},"statuses":{"href":"https://api.github.com/repos/recurly/recurly-client-ruby/statuses/cee7cf87fac88e7b2a8aa4a0ce57062ac020419e"}}}}