Update samples/integration tests
This commit is contained in:
parent
9e738cc82a
commit
808d683d9a
|
@ -13,9 +13,9 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
require 'googleauth'
|
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 = Pubsub::PubsubService.new
|
||||||
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
|
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 = Pubsub::PublishRequest.new(messages: [])
|
||||||
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'Hello')
|
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'Hello')
|
||||||
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'World')
|
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'World')
|
||||||
pubsub.publish(topic, request)
|
pubsub.publish_topic(topic, request)
|
||||||
|
|
||||||
# Pull messages
|
# 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|
|
response.received_messages.each do |received_message|
|
||||||
data = received_message.message.data
|
data = received_message.message.data
|
||||||
puts "Received #{data}"
|
puts "Received #{data}"
|
||||||
|
@ -44,9 +44,8 @@ end
|
||||||
|
|
||||||
# Acknowledge receipt
|
# Acknowledge receipt
|
||||||
ack_ids = response.received_messages.map{ |msg| msg.ack_id }
|
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
|
# Delete the subscription & topic
|
||||||
pubsub.delete_subscription(subscription)
|
pubsub.delete_subscription(subscription)
|
||||||
pubsub.delete_topic(topic)
|
pubsub.delete_topic(topic)
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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
|
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!')
|
result = translate.list_translations(source: 'en', target: 'es', q: 'Hello world!')
|
||||||
puts result.translations.first.translated_text
|
puts result.translations.first.translated_text
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -23,10 +23,10 @@ RSpec.describe Google::Apis::PubsubV1beta2, :if => run_integration_tests? do
|
||||||
request = Pubsub::PublishRequest.new(messages: [])
|
request = Pubsub::PublishRequest.new(messages: [])
|
||||||
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'Hello')
|
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'Hello')
|
||||||
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'World')
|
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'World')
|
||||||
@pubsub.publish(@topic_name, request)
|
@pubsub.publish_topic(@topic_name, request)
|
||||||
|
|
||||||
# Pull messages
|
# 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|
|
response.received_messages.each do |received_message|
|
||||||
data = received_message.message.data
|
data = received_message.message.data
|
||||||
puts "Received #{data}"
|
puts "Received #{data}"
|
||||||
|
@ -34,7 +34,7 @@ RSpec.describe Google::Apis::PubsubV1beta2, :if => run_integration_tests? do
|
||||||
|
|
||||||
# Acknowledge receipt
|
# Acknowledge receipt
|
||||||
ack_ids = response.received_messages.map{ |msg| msg.ack_id }
|
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
|
expect(response.received_messages.length).to eq 2
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue