trav3 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97c7a3e7bbfb1ec5effd12bf275cf1e0bff1e39ed6676531648fb77c8ea329b4
4
- data.tar.gz: '0683ce386cf9c469fb9f404321cb9de550141106a70dd4f12454d51f5ace73ed'
3
+ metadata.gz: 1c8f0f2a7f7113828e1f3099a0fb788f72edc9d884d24e3c78eb7a783b19bf51
4
+ data.tar.gz: 43dcf547f4ac6c76c41dd22c761b68f8bfd955eee2d03add7b490eae22e5ca67
5
5
  SHA512:
6
- metadata.gz: 4c0c20dead40f8acff9ba0002e0e87b11fea7f8451ef425b4fff3d27a29cc5896484c6fc0297a757ab525cf1964d625492fdc85cc11162dcb3ef069b7675e7ba
7
- data.tar.gz: 4dab80633ae6036f7574e92fc599db46e669627b9812fea3464f4689909c1872a230770f14c4acef3d606ed79c604bb86902d97253327578d2485ee6e02f8a92
6
+ metadata.gz: 953961e841c122143f2943baf20364dfbff7ee2e6d7d3620b1dd347508eef73a2639199f730c1f1aa49b73255c979c5092bc038bb1e69c0ca5086c0faef332fa
7
+ data.tar.gz: caf9a299840303e51b18d91185e2f210b9cf4b8a3a01adc92b1e1b7013c3fab7000a810594c075998d503b9073cd1e0a6a4878a1bc88c5c6ccb612f148a8928e
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/trav3.svg)](http://badge.fury.io/rb/trav3)
2
2
  [![Build Status](https://travis-ci.org/danielpclark/trav3.svg?branch=master)](https://travis-ci.org/danielpclark/trav3)
3
- [![Commits Since Release](https://img.shields.io/github/commits-since/danielpclark/trav3/v0.3.1.svg)](https://github.com/danielpclark/trav3/graphs/commit-activity)
3
+ [![Commits Since Release](https://img.shields.io/github/commits-since/danielpclark/trav3/v0.3.2.svg)](https://github.com/danielpclark/trav3/graphs/commit-activity)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/1ed07a4baea3832b6207/maintainability)](https://codeclimate.com/github/danielpclark/trav3/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/1ed07a4baea3832b6207/test_coverage)](https://codeclimate.com/github/danielpclark/trav3/test_coverage)
6
6
  [![Red The Docs](https://img.shields.io/badge/Read-the%20docs-blue.svg)](http://danielpclark.github.io/trav3/Trav3/Travis.html)
@@ -37,12 +37,12 @@ module Trav3
37
37
 
38
38
  initial_defaults
39
39
  end
40
+ # rubocop:disable Lint/Void
40
41
 
41
42
  # Set as the API endpoint
42
43
  #
43
44
  # @param endpoint [String] name for value to set
44
45
  # @return [self]
45
- # rubocop:disable Lint/Void
46
46
  def api_endpoint=(endpoint)
47
47
  validate_api_endpoint endpoint
48
48
 
@@ -50,7 +50,16 @@ module Trav3
50
50
 
51
51
  self
52
52
  end
53
- # rubocop:enable Lint/Void
53
+
54
+ # Set the authorization token in the requests' headers
55
+ #
56
+ # @param token [String] sets authorization token header
57
+ # @return [self]
58
+ def authorization=(token)
59
+ validate_string token
60
+ h('Authorization': "token #{token}")
61
+ self
62
+ end
54
63
 
55
64
  # Set as many options as you'd like for collections queried via an API request
56
65
  #
@@ -79,10 +88,13 @@ module Trav3
79
88
  # Change the repository this instance of `Trav3::Travis` uses.
80
89
  #
81
90
  # @param repo_name [String] github_username/repository_name
91
+ # @return [self]
82
92
  def repository=(repo_name)
83
93
  validate_repo_format repo_name
84
94
  @repo = sanitize_repo_name repo_name
95
+ self
85
96
  end
97
+ # rubocop:enable Lint/Void
86
98
 
87
99
  # Please Note that the naming of this endpoint may be changed. Our naming convention for this information is in flux. If you have suggestions for how this information should be presented please leave us feedback by commenting in this issue here or emailing support support@travis-ci.com.
88
100
  #
@@ -111,7 +123,7 @@ module Trav3
111
123
  # GET <code>/owner/{user.login}/active</code>
112
124
  #
113
125
  # Template Variable Type Description
114
- # user.login String Login set on Github.
126
+ # user.login String Login set on GitHub.
115
127
  # Query Parameter Type Description
116
128
  # include [String] List of attributes to eager load.
117
129
  #
@@ -138,11 +150,8 @@ module Trav3
138
150
  # @param owner [String] username, organization name, or github id
139
151
  # @return [Success, RequestError]
140
152
  def active(owner = username)
141
- if number? owner
142
- get("#{without_repo}/owner/github_id/#{owner}/active")
143
- else
144
- get("#{without_repo}/owner/#{owner}/active")
145
- end
153
+ number?(owner) and return get("#{without_repo}/owner/github_id/#{owner}/active")
154
+ get("#{without_repo}/owner/#{owner}/active")
146
155
  end
147
156
 
148
157
  # The branch of a GitHub repository. Useful for obtaining information about the last build on a given branch.
@@ -354,7 +363,7 @@ module Trav3
354
363
  #
355
364
  # Example: POST /build/86601346/restart
356
365
  #
357
- # @note POST requests require an authorization token set in the headers. See: {h}
366
+ # @note POST requests require an authorization token set in the headers. See: {authorization=}
358
367
  #
359
368
  # @param build_id [String, Integer] the build id number
360
369
  # @param option [Symbol] options for :cancel or :restart
@@ -644,16 +653,262 @@ module Trav3
644
653
  #
645
654
  # Example: DELETE /repo/rails%2Frails/caches
646
655
  #
647
- # @note DELETE requests require an authorization token set in the headers. See: {h}
656
+ # @note DELETE requests require an authorization token set in the headers. See: {authorization=}
648
657
  #
649
658
  # @param delete [Boolean] option for deleting cache(s)
650
659
  # @return [Success, RequestError]
651
660
  def caches(delete = false)
652
- if delete
653
- without_limit { delete("#{with_repo}/caches#{opts}") }
654
- else
655
- get("#{with_repo}/caches")
661
+ delete and return without_limit { delete("#{with_repo}/caches#{opts}") }
662
+ get("#{with_repo}/caches")
663
+ end
664
+
665
+ # An individual environment variable.
666
+ #
667
+ # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
668
+ #
669
+ # ## Attributes
670
+ #
671
+ # **Standard Representation**
672
+ #
673
+ # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
674
+ #
675
+ # Name Type Description
676
+ # id String The environment variable id.
677
+ # name String The environment variable name, e.g. FOO.
678
+ # value String The environment variable's value, e.g. bar.
679
+ # public Boolean Whether this environment variable should be publicly visible or not.
680
+ #
681
+ # **Minimal Representation**
682
+ #
683
+ # Included when the resource is returned as part of another resource.
684
+ #
685
+ # Name Type Description
686
+ # id String The environment variable id.
687
+ # name String The environment variable name, e.g. FOO.
688
+ # public Boolean Whether this environment variable should be publicly visible or not.
689
+ #
690
+ # ## Actions
691
+ #
692
+ # **Find**
693
+ #
694
+ # This returns a single environment variable. It is possible to use the repository id or slug in the request.
695
+ #
696
+ # GET <code>/repo/{repository.id}/env_var/{env_var.id}</code>
697
+ #
698
+ # Template Variable Type Description
699
+ # repository.id Integer Value uniquely identifying the repository.
700
+ # env_var.id String The environment variable id.
701
+ # Query Parameter Type Description
702
+ # env_var.id String The environment variable id.
703
+ # id String Alias for env_var.id.
704
+ # include [String] List of attributes to eager load.
705
+ # repository.id Integer Value uniquely identifying the repository.
706
+ #
707
+ # GET <code>/repo/{repository.slug}/env_var/{env_var.id}</code>
708
+ #
709
+ # Template Variable Type Description
710
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
711
+ # env_var.id String The environment variable id.
712
+ # Query Parameter Type Description
713
+ # env_var.id String The environment variable id.
714
+ # id String Alias for env_var.id.
715
+ # include [String] List of attributes to eager load.
716
+ # repository.id Integer Value uniquely identifying the repository.
717
+ #
718
+ # **Update**
719
+ #
720
+ # This updates a single environment variable. It is possible to use the repository id or slug in the request.
721
+ #
722
+ # Use namespaced params in the request body to pass the new environment variable:
723
+ #
724
+ # ```bash
725
+ # curl -X PATCH \
726
+ # -H "Content-Type: application/json" \
727
+ # -H "Travis-API-Version: 3" \
728
+ # -H "Authorization: token xxxxxxxxxxxx" \
729
+ # -d '{ "env_var.value": "bar", "env_var.public": false }' \
730
+ # https://api.travis-ci.com/repo/1234/{env_var.id}
731
+ # ```
732
+ #
733
+ # PATCH <code>/repo/{repository.id}/env_var/{env_var.id}</code>
734
+ #
735
+ # Template Variable Type Description
736
+ # repository.id Integer Value uniquely identifying the repository.
737
+ # env_var.id String The environment variable id.
738
+ # Accepted Parameter Type Description
739
+ # env_var.name String The environment variable name, e.g. FOO.
740
+ # env_var.value String The environment variable's value, e.g. bar.
741
+ # env_var.public Boolean Whether this environment variable should be publicly visible or not.
742
+ #
743
+ # PATCH <code>/repo/{repository.slug}/env_var/{env_var.id}</code>
744
+ #
745
+ # Template Variable Type Description
746
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
747
+ # env_var.id String The environment variable id.
748
+ # Accepted Parameter Type Description
749
+ # env_var.name String The environment variable name, e.g. FOO.
750
+ # env_var.value String The environment variable's value, e.g. bar.
751
+ # env_var.public Boolean Whether this environment variable should be publicly visible or not.
752
+ #
753
+ # **Delete**
754
+ #
755
+ # This deletes a single environment variable. It is possible to use the repository id or slug in the request.
756
+ #
757
+ # DELETE <code>/repo/{repository.id}/env_var/{env_var.id}</code>
758
+ #
759
+ # Template Variable Type Description
760
+ # repository.id Integer Value uniquely identifying the repository.
761
+ # env_var.id String The environment variable id.
762
+ #
763
+ # DELETE <code>/repo/{repository.slug}/env_var/{env_var.id}</code>
764
+ #
765
+ # Template Variable Type Description
766
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
767
+ # env_var.id String The environment variable id.
768
+ #
769
+ # @overload env_var(env_var_id)
770
+ # Gets current env var
771
+ # @param env_var_id [String] environment variable id
772
+ # @overload env_var(env_var_id, action: params)
773
+ # Performs action per specific key word argument
774
+ # @param env_var_id [String] environment variable id
775
+ # @param update [Hash] Optional keyword argument. Update key pair with hash `{ value: "new value" }`
776
+ # @param delete [Boolean] Optional keyword argument. Use truthy value to delete current key pair
777
+ # @return [Success, RequestError]
778
+ def env_var(env_var_id, update: nil, delete: nil)
779
+ raise 'Too many options specified' unless [update, delete].compact.count < 2
780
+
781
+ validate_string env_var_id
782
+
783
+ update and return patch("#{with_repo}/env_var/#{env_var_id}", env_var_keys(update))
784
+ delete and return delete("#{with_repo}/env_var/#{env_var_id}")
785
+ get("#{with_repo}/env_var/#{env_var_id}")
786
+ end
787
+
788
+ # A list of environment variables.
789
+ #
790
+ # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
791
+ #
792
+ # ## Attributes
793
+ #
794
+ # Name Type Description
795
+ # env_vars [Env var] List of env_vars.
796
+ #
797
+ # ## Actions
798
+ #
799
+ # **For Repository**
800
+ #
801
+ # This returns a list of environment variables for an individual repository. It is possible to use the repository id or slug in the request.
802
+ #
803
+ # GET <code>/repo/{repository.id}/env_vars</code>
804
+ #
805
+ # Template Variable Type Description
806
+ # repository.id Integer Value uniquely identifying the repository.
807
+ # Query Parameter Type Description
808
+ # include [String] List of attributes to eager load.
809
+ #
810
+ # Example: GET /repo/891/env_vars
811
+ #
812
+ # GET <code>/repo/{repository.slug}/env_vars</code>
813
+ #
814
+ # Template Variable Type Description
815
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
816
+ # Query Parameter Type Description
817
+ # include [String] List of attributes to eager load.
818
+ #
819
+ # Example: GET /repo/rails%2Frails/env_vars
820
+ #
821
+ # **Create**
822
+ #
823
+ # This creates an environment variable for an individual repository. It is possible to use the repository id or slug in the request.
824
+ #
825
+ # Use namespaced params in the request body to pass the new environment variables:
826
+ #
827
+ # ```bash
828
+ # curl -X POST \
829
+ # -H "Content-Type: application/json" \
830
+ # -H "Travis-API-Version: 3" \
831
+ # -H "Authorization: token xxxxxxxxxxxx" \
832
+ # -d '{ "env_var.name": "FOO", "env_var.value": "bar", "env_var.public": false }' \
833
+ # https://api.travis-ci.com/repo/1234/env_vars
834
+ # ```
835
+ #
836
+ # POST <code>/repo/{repository.id}/env_vars</code>
837
+ #
838
+ # Template Variable Type Description
839
+ # repository.id Integer Value uniquely identifying the repository.
840
+ # Accepted Parameter Type Description
841
+ # env_var.name String The environment variable name, e.g. FOO.
842
+ # env_var.value String The environment variable's value, e.g. bar.
843
+ # env_var.public Boolean Whether this environment variable should be publicly visible or not.
844
+ #
845
+ # Example: POST /repo/891/env_vars
846
+ #
847
+ # POST <code>/repo/{repository.slug}/env_vars</code>
848
+ #
849
+ # Template Variable Type Description
850
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
851
+ # Accepted Parameter Type Description
852
+ # env_var.name String The environment variable name, e.g. FOO.
853
+ # env_var.value String The environment variable's value, e.g. bar.
854
+ # env_var.public Boolean Whether this environment variable should be publicly visible or not.
855
+ #
856
+ # Example: POST /repo/rails%2Frails/env_vars
857
+ #
858
+ # @note requests require an authorization token set in the headers. See: {authorization=}
859
+ #
860
+ # @param create [Hash] Optional argument. A hash of the `name`, `value`, and `public` visibleness for a env var to create
861
+ # @return [Success, RequestError]
862
+ def env_vars(create = nil)
863
+ if create
864
+ validate_env_var create
865
+
866
+ return create("#{with_repo}/env_vars", env_var_keys(create))
656
867
  end
868
+
869
+ get("#{with_repo}/env_vars")
870
+ end
871
+
872
+ # A GitHub App installation.
873
+ #
874
+ # ## Attributes
875
+ #
876
+ # **Minimal Representation**
877
+ #
878
+ # Included when the resource is returned as part of another resource.
879
+ #
880
+ # Name Type Description
881
+ # id Integer The installation id.
882
+ # github_id Integer The installation's id on GitHub.
883
+ #
884
+ # **Standard Representation**
885
+ #
886
+ # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
887
+ #
888
+ # Name Type Description
889
+ # id Integer The installation id.
890
+ # github_id Integer The installation's id on GitHub.
891
+ # owner Owner GitHub user or organization the installation belongs to.
892
+ #
893
+ # ## Actions
894
+ #
895
+ # **Find**
896
+ #
897
+ # This returns a single installation.
898
+ #
899
+ # GET <code>/installation/{installation.github_id}</code>
900
+ #
901
+ # Template Variable Type Description
902
+ # installation.github_id Integer The installation's id on GitHub.
903
+ # Query Parameter Type Description
904
+ # include [String] List of attributes to eager load.
905
+ #
906
+ # @param installation_id [String, Integer] GitHub App installation id
907
+ # @return [Success, RequestError]
908
+ def installation(installation_id)
909
+ validate_number installation_id
910
+
911
+ get("#{without_repo}/installation/#{installation_id}")
657
912
  end
658
913
 
659
914
  # An individual job.
@@ -736,7 +991,7 @@ module Trav3
736
991
  #
737
992
  # Example: POST /job/86601347/debug
738
993
  #
739
- # @note POST requests require an authorization token set in the headers. See: {h}
994
+ # @note POST requests require an authorization token set in the headers. See: {authorization=}
740
995
  #
741
996
  # @param job_id [String, Integer] the job id number
742
997
  # @param option [Symbol] options for :cancel, :restart, or :debug
@@ -886,16 +1141,16 @@ module Trav3
886
1141
  #
887
1142
  # Example: DELETE /repo/rails%2Frails/key_pair
888
1143
  #
889
- # @note requests require an authorization token set in the headers. See: {h}
1144
+ # @note requests require an authorization token set in the headers. See: {authorization=}
890
1145
  # @note API enpoint needs to be set to `https://api.travis-ci.com` See: {api_endpoint=}
891
1146
  #
892
- # @overload key_par()
1147
+ # @overload key_pair()
893
1148
  # Gets current key_pair if any
894
1149
  # @overload key_pair(action: params)
895
1150
  # Performs action per specific key word argument
896
- # @param create [Hash] Create a new key pair from provided private key { description: "name", value: "private key" }
897
- # @param update [Hash] Update key pair with hash { description: "new name" }
898
- # @param delete [Boolean] Use truthy value to delete current key pair
1151
+ # @param create [Hash] Optional keyword argument. Create a new key pair from provided private key `{ description: "name", value: "private key" }`
1152
+ # @param update [Hash] Optional keyword argument. Update key pair with hash `{ description: "new name" }`
1153
+ # @param delete [Boolean] Optional keyword argument. Use truthy value to delete current key pair
899
1154
  # @return [Success, RequestError]
900
1155
  def key_pair(create: nil, update: nil, delete: nil)
901
1156
  raise 'Too many options specified' unless [create, update, delete].compact.count < 2
@@ -972,7 +1227,7 @@ module Trav3
972
1227
  #
973
1228
  # Example: POST /repo/rails%2Frails/key_pair/generated
974
1229
  #
975
- # @note requests require an authorization token set in the headers. See: {h}
1230
+ # @note requests require an authorization token set in the headers. See: {authorization=}
976
1231
  #
977
1232
  # @param action [String, Symbol] defaults to getting current key pair, use `:create` if you would like to generate a new key pair
978
1233
  # @return [Success, RequestError]
@@ -1300,7 +1555,7 @@ module Trav3
1300
1555
  # GET <code>/owner/{user.login}</code>
1301
1556
  #
1302
1557
  # Template Variable Type Description
1303
- # user.login String Login set on Github.
1558
+ # user.login String Login set on GitHub.
1304
1559
  #
1305
1560
  # Query Parameter Type Description
1306
1561
  # include [String] List of attributes to eager load.
@@ -1330,11 +1585,8 @@ module Trav3
1330
1585
  # @param owner [String] username or github id
1331
1586
  # @return [Success, RequestError]
1332
1587
  def owner(owner = username)
1333
- if number? owner
1334
- get("#{without_repo}/owner/github_id/#{owner}")
1335
- else
1336
- get("#{without_repo}/owner/#{owner}")
1337
- end
1588
+ number?(owner) and return get("#{without_repo}/owner/github_id/#{owner}")
1589
+ get("#{without_repo}/owner/#{owner}")
1338
1590
  end
1339
1591
 
1340
1592
  # Document `resources/preference/overview` not found.
@@ -1401,7 +1653,7 @@ module Trav3
1401
1653
  # Query Parameter Type Description
1402
1654
  # include [String] List of attributes to eager load.
1403
1655
  #
1404
- # @note requests require an authorization token set in the headers. See: {h}
1656
+ # @note requests require an authorization token set in the headers. See: {authorization=}
1405
1657
  #
1406
1658
  # @param key [String] preference name to get or set
1407
1659
  # @param value [String] optional value to set preference
@@ -1413,11 +1665,8 @@ module Trav3
1413
1665
  org_id = "/org/#{org_id}"
1414
1666
  end
1415
1667
 
1416
- if value.nil?
1417
- get("#{without_repo}#{org_id}/preference/#{key}")
1418
- else
1419
- patch("#{without_repo}#{org_id}/preference/#{key}", 'preference.value' => value)
1420
- end
1668
+ value and return patch("#{without_repo}#{org_id}/preference/#{key}", 'preference.value' => value)
1669
+ get("#{without_repo}#{org_id}/preference/#{key}")
1421
1670
  end
1422
1671
 
1423
1672
  # Document `resources/preferences/overview` not found.
@@ -1453,7 +1702,7 @@ module Trav3
1453
1702
  #
1454
1703
  # Example: GET /preferences
1455
1704
  #
1456
- # @note requests require an authorization token set in the headers. See: {h}
1705
+ # @note requests require an authorization token set in the headers. See: {authorization=}
1457
1706
  #
1458
1707
  # @param org_id [String, Integer] optional organization id
1459
1708
  # @return [Success, RequestError]
@@ -1521,7 +1770,7 @@ module Trav3
1521
1770
  # GET <code>/owner/{user.login}/repos</code>
1522
1771
  #
1523
1772
  # Template Variable Type Description
1524
- # user.login String Login set on Github.
1773
+ # user.login String Login set on GitHub.
1525
1774
  #
1526
1775
  # Query Parameter Type Description
1527
1776
  # active [Boolean] Alias for repository.active.
@@ -1606,11 +1855,8 @@ module Trav3
1606
1855
  # @param owner [String] username or github id
1607
1856
  # @return [Success, RequestError]
1608
1857
  def repositories(owner = username)
1609
- if number? owner
1610
- get("#{without_repo}/owner/github_id/#{owner}/repos#{opts}")
1611
- else
1612
- get("#{without_repo}/owner/#{owner}/repos#{opts}")
1613
- end
1858
+ number?(owner) and return get("#{without_repo}/owner/github_id/#{owner}/repos#{opts}")
1859
+ get("#{without_repo}/owner/#{owner}/repos#{opts}")
1614
1860
  end
1615
1861
 
1616
1862
  # An individual repository.
@@ -1740,7 +1986,7 @@ module Trav3
1740
1986
  #
1741
1987
  # Example: POST /repo/rails%2Frails/unstar
1742
1988
  #
1743
- # @note POST requests require an authorization token set in the headers. See: {h}
1989
+ # @note POST requests require an authorization token set in the headers. See: {authorization=}
1744
1990
  #
1745
1991
  # @param repo [String] github_username/repository_name
1746
1992
  # @param action [String, Symbol] Optional argument for star/unstar/activate/deactivate
@@ -1751,13 +1997,9 @@ module Trav3
1751
1997
  validate_repo_format repo
1752
1998
 
1753
1999
  repo = sanitize_repo_name repo
1754
- action = '' unless %w[star unstar activate deactivate].include? action.to_s
1755
2000
 
1756
- if action.empty?
1757
- get("#{without_repo}/repo/#{repo}")
1758
- else
1759
- post("#{without_repo}/repo/#{repo}/#{action}")
1760
- end
2001
+ action and return post("#{without_repo}/repo/#{repo}/#{action}")
2002
+ get("#{without_repo}/repo/#{repo}")
1761
2003
  end
1762
2004
 
1763
2005
  # An individual request
@@ -2160,7 +2402,7 @@ module Trav3
2160
2402
  #
2161
2403
  # Name Type Description
2162
2404
  # id Integer Value uniquely identifying the user.
2163
- # login String Login set on Github.
2405
+ # login String Login set on GitHub.
2164
2406
  #
2165
2407
  # **Standard Representation**
2166
2408
  #
@@ -2168,13 +2410,13 @@ module Trav3
2168
2410
  #
2169
2411
  # Name Type Description
2170
2412
  # id Integer Value uniquely identifying the user.
2171
- # login String Login set on Github.
2413
+ # login String Login set on GitHub.
2172
2414
  # name String Name set on GitHub.
2173
2415
  # github_id Integer Id set on GitHub.
2174
2416
  # avatar_url String Avatar URL set on GitHub.
2175
2417
  # education Boolean Whether or not the user has an education account.
2176
2418
  # allow_migration Unknown The user's allow_migration.
2177
- # is_syncing Boolean Whether or not the user is currently being synced with Github.
2419
+ # is_syncing Boolean Whether or not the user is currently being synced with GitHub.
2178
2420
  # synced_at String The last time the user was synced with GitHub.
2179
2421
  #
2180
2422
  # **Additional Attributes**
@@ -2222,10 +2464,10 @@ module Trav3
2222
2464
  # Example: GET /user
2223
2465
  #
2224
2466
  # @note sync feature may not be permitted
2225
- # @note POST requests require an authorization token set in the headers. See: {h}
2467
+ # @note POST requests require an authorization token set in the headers. See: {authorization=}
2226
2468
  #
2227
2469
  # @param user_id [String, Integer] optional user id
2228
- # @param sync [Boolean] optional argument for syncing your Travis CI account with Github
2470
+ # @param sync [Boolean] optional argument for syncing your Travis CI account with GitHub
2229
2471
  # @raise [TypeError] if given user id is not a number
2230
2472
  # @return [Success, RequestError]
2231
2473
  def user(user_id = nil, sync = false)
@@ -2233,11 +2475,8 @@ module Trav3
2233
2475
 
2234
2476
  validate_number user_id
2235
2477
 
2236
- if sync
2237
- get("#{without_repo}/user/#{user_id}/sync")
2238
- else
2239
- get("#{without_repo}/user/#{user_id}")
2240
- end
2478
+ sync and return get("#{without_repo}/user/#{user_id}/sync")
2479
+ get("#{without_repo}/user/#{user_id}")
2241
2480
  end
2242
2481
 
2243
2482
  private # @private
@@ -2250,6 +2489,10 @@ module Trav3
2250
2489
  Trav3::REST.delete(self, url)
2251
2490
  end
2252
2491
 
2492
+ def env_var_keys(hash)
2493
+ inject_property_name('env_var', hash)
2494
+ end
2495
+
2253
2496
  def get(url, raw_reply = false)
2254
2497
  Trav3::REST.get(self, url, raw_reply)
2255
2498
  end
@@ -2273,8 +2516,12 @@ module Trav3
2273
2516
  h('Travis-API-Version': 3)
2274
2517
  end
2275
2518
 
2519
+ def inject_property_name(name, hash)
2520
+ hash.map { |k, v| ["#{name}.#{k}", v] }.to_h unless hash.keys.first.match?(/#{name}\.\w+/)
2521
+ end
2522
+
2276
2523
  def key_pair_keys(hash)
2277
- hash.map { |k, v| ["key_pair.#{k}", v] }.to_h unless hash.keys.first.match?(/key_pair\.\w+/)
2524
+ inject_property_name('key_pair', hash)
2278
2525
  end
2279
2526
 
2280
2527
  def number?(input)
@@ -2297,6 +2544,21 @@ module Trav3
2297
2544
  raise InvalidAPIEndpoint unless /^https:\/\/api\.travis-ci\.(?:org|com)$/.match? input
2298
2545
  end
2299
2546
 
2547
+ # rubocop:disable Metrics/CyclomaticComplexity
2548
+ def validate_env_var(input)
2549
+ raise TypeError, "Hash expected, #{input.class} given" unless input.is_a? Hash
2550
+ raise EnvVarError unless input.all? do |k, v|
2551
+ k.match?(/name|value|public/) &&
2552
+ case k.to_s
2553
+ when /name/ then v.is_a? String
2554
+ when /value/ then v.is_a? String
2555
+ when /public/ then [true, false].include? v
2556
+ else false
2557
+ end
2558
+ end
2559
+ end
2560
+ # rubocop:enable Metrics/CyclomaticComplexity
2561
+
2300
2562
  def validate_number(input)
2301
2563
  raise TypeError, "Integer expected, #{input.class} given" unless number? input
2302
2564
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trav3
4
+ class EnvVarError < StandardError
5
+ def message
6
+ "You must provide the keys `name`, `value`, and `public`\
7
+ where name and value are given String values and public is a Boolean."
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trav3
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trav3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
@@ -86,6 +86,7 @@ files:
86
86
  - bin/console
87
87
  - bin/setup
88
88
  - lib/trav3.rb
89
+ - lib/trav3/error/env_var_error.rb
89
90
  - lib/trav3/error/invalid_api_endpoint.rb
90
91
  - lib/trav3/error/invalid_repository.rb
91
92
  - lib/trav3/error/unimplemented.rb