From 808d683d9ad1beae97f81736b9defde4e0f75836 Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Mon, 14 Dec 2015 17:42:53 -0800 Subject: [PATCH] Update samples/integration tests --- samples/pubsub/pubsub.rb | 11 +++++----- samples/translate/translate.rb | 6 +----- spec/integration_tests/adsense_spec.rb | 28 ++++++++++++++++++++++++++ spec/integration_tests/pubsub_spec.rb | 6 +++--- 4 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 spec/integration_tests/adsense_spec.rb diff --git a/samples/pubsub/pubsub.rb b/samples/pubsub/pubsub.rb index 1fdbdf987..13b436196 100644 --- a/samples/pubsub/pubsub.rb +++ b/samples/pubsub/pubsub.rb @@ -13,9 +13,9 @@ # limitations under the License. require 'googleauth' -require 'google/apis/pubsub_v1beta2' +require 'google/apis/pubsub_v1' -Pubsub = Google::Apis::PubsubV1beta2 +Pubsub = Google::Apis::PubsubV1 pubsub = Pubsub::PubsubService.new pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB]) @@ -33,10 +33,10 @@ pubsub.create_subscription(subscription, Pubsub::Subscription.new(topic: topic)) request = Pubsub::PublishRequest.new(messages: []) request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'Hello') request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'World') -pubsub.publish(topic, request) +pubsub.publish_topic(topic, request) # Pull messages -response = pubsub.pull(subscription, Pubsub::PullRequest.new(max_messages: 5)) +response = pubsub.pull_subscription(subscription, Pubsub::PullRequest.new(max_messages: 5)) response.received_messages.each do |received_message| data = received_message.message.data puts "Received #{data}" @@ -44,9 +44,8 @@ end # Acknowledge receipt ack_ids = response.received_messages.map{ |msg| msg.ack_id } -pubsub.acknowledge(subscription, Pubsub::AcknowledgeRequest.new(ack_ids: ack_ids)) +pubsub.acknowledge_subscription(subscription, Pubsub::AcknowledgeRequest.new(ack_ids: ack_ids)) # Delete the subscription & topic pubsub.delete_subscription(subscription) pubsub.delete_topic(topic) - diff --git a/samples/translate/translate.rb b/samples/translate/translate.rb index 30a506d0b..661f9d3ed 100644 --- a/samples/translate/translate.rb +++ b/samples/translate/translate.rb @@ -12,11 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'tempfile' -require 'googleauth' -require 'google/apis/translate_v2' -Google::Apis.logger.level = Logger::DEBUG +require 'google/apis/translate_v2' Translate = Google::Apis::TranslateV2 @@ -25,4 +22,3 @@ translate.key = ARGV[0] || 'YOUR_API_KEY' result = translate.list_translations(source: 'en', target: 'es', q: 'Hello world!') puts result.translations.first.translated_text - diff --git a/spec/integration_tests/adsense_spec.rb b/spec/integration_tests/adsense_spec.rb new file mode 100644 index 000000000..2a56a3d1a --- /dev/null +++ b/spec/integration_tests/adsense_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' +require 'google/apis/adsense_v1_4' +require 'googleauth' + +Adsense = Google::Apis::AdsenseV1_4 + +RSpec.describe Google::Apis::AdsenseV1_4, :if => run_integration_tests? do + + before(:context) do + #WebMock.allow_net_connect! + @adsense = Adsense::AdSenseService.new + #@adsense.authorization = Google::Auth.get_application_default([Adsense::AUTH_ADSENSE]) + #@adsense.authorization.sub = 'cb@travelingnuker.com' + #@adsense.authorization.fetch_access_token! + end + + it 'should download a report with multiple dimensions' do + report = @adsense.generate_report( Date.today.to_s, Date.today.to_s, dimension: ["DATE", "AD_UNIT_NAME"] ) + + report_header_names = report.headers.map { |h| h.name } + expect(report_header_names).to include('DATE') + expect(report_header_names).to include('AD_UNIT_NAME') + end + + after(:context) do + #WebMock.disable_net_connect! + end +end diff --git a/spec/integration_tests/pubsub_spec.rb b/spec/integration_tests/pubsub_spec.rb index ee4fd2e7f..dabb16a1a 100644 --- a/spec/integration_tests/pubsub_spec.rb +++ b/spec/integration_tests/pubsub_spec.rb @@ -23,10 +23,10 @@ RSpec.describe Google::Apis::PubsubV1beta2, :if => run_integration_tests? do request = Pubsub::PublishRequest.new(messages: []) request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'Hello') request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'World') - @pubsub.publish(@topic_name, request) + @pubsub.publish_topic(@topic_name, request) # Pull messages - response = @pubsub.pull(@subscription_name, Pubsub::PullRequest.new(max_messages: 5)) + response = @pubsub.pull_subscription(@subscription_name, Pubsub::PullRequest.new(max_messages: 5)) response.received_messages.each do |received_message| data = received_message.message.data puts "Received #{data}" @@ -34,7 +34,7 @@ RSpec.describe Google::Apis::PubsubV1beta2, :if => run_integration_tests? do # Acknowledge receipt ack_ids = response.received_messages.map{ |msg| msg.ack_id } - @pubsub.acknowledge(@subscription_name, Pubsub::AcknowledgeRequest.new(ack_ids: ack_ids)) + @pubsub.acknowledge_subscription(@subscription_name, Pubsub::AcknowledgeRequest.new(ack_ids: ack_ids)) expect(response.received_messages.length).to eq 2 end